{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":22239,"path":"integrate-applications/system-import-sets/t_AddOnBeforeScriptToTransformMap.md","title":"Add onBefore scripts to the transform map","bundle":null,"doc_type":null,"release":"australia","body":"\n# Add onBefore scripts to the transform map\n\nCreate one onBefore transform map script to copy the sys\\_id of new records from the source to the target instance. Create a second onBefore transform map script to identify records on the target instance that have the same unique values but different sys\\_id values.\n\n## Before you begin\n\nRole required: admin.\n\n## Procedure\n\n1.  Open the table transform map record you created.\n\n2.  In the **Transform Scripts** related list, click **New**.\n\n3.  In the **When** field, select **onBefore**.\n\n4.  Enter the following script:\n\n    ```\n    if (action == \"insert\") {target.setNewGuidValue(source.u_sys_id); }\n    ```\n\n5.  Click **Submit**.\n\n6.  In the **Transform Scripts** related list, click **New**.\n\n7.  In the **When** field, select **onBefore**.\n\n8.  Enter the following **Script**:\n\n    ```\n    /** \n    * This script queries for a uniquely identifying value of the referenced record and then \n    * updates the target reference field with the sys_id of the matching target record.\n    * This sample assumes:\n    * 1) The target table contains an assigned_to field which is a reference field.\n    * 2) The reference field references the User [sys_user] table.\n    * 3) You can use the email field to uniquely identify users. Alternatively you\n    *    could use the user_name field.\n    */\n    var ref = new GlideRecord(\"sys_user\"); //Replace sys_user with any reference table\n    ref.addQuery(\"email\", source.email); //Replace email with any unique field\n    ref.query();\n    if(ref.next()){\n       target.assigned_to = ref.sys_id; //Replace assigned_to with any reference field\n    }\n    ```\n\n9.  Click **Submit**.\n\n\n**Parent Topic:**[Using XML import sets](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/c_XMLImportSets.md)\n\n**Previous topic:**[Create a transform map](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/t_CreateATransformMap.md)\n\n**Next topic:**[Retrieving data from a CSV formatted file](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/t_RetrieveDataFromACSVFormatFile.md)\n\n"}}