{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":22232,"path":"integrate-applications/system-import-sets/r_MapWithTransformationEventScripts.md","title":"Map with transformation event scripts","bundle":null,"doc_type":null,"release":"australia","body":"\n# Map with transformation event scripts\n\nTransformation events occur during the process of transforming an import set table onto a table.\n\nThese events modify the transformation behavior from any type of mapping specification. Transformation Event scripts modify the processing of the events at various stages of the transformation.\n\nFor example, the processing of a mapping operation defined using the [Mapping Assist Utility](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/c_MappingOptions.md) can be manipulated using the event scripts. There are a number of import set JavaScript objects that are accessible during these events. These objects represent tables or portions of tables. It is important to note that what these objects refer to varies depending on the context of the event in which they are referenced.\n\nThe following is a table of all of the transform events and their contextual variables.\n\n**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n<table id=\"table_r1y_4rs_sq\"><thead><tr><th>\n\nEvent name\n\n</th><th>\n\nEvent Parameters\n\n</th></tr></thead><tbody><tr><td>\n\nonStart\n\n</td><td>\n\nWhen: The onStart event script is processed at the start of an import run, before any data rows are read.\n\n <table id=\"table_vjh_wrs_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onStart import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe first row of the source table, there is no data yet since the row has not been read.\n\n</td></tr><tr><td>\n\nimport\\_set\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe import set that is currently being transformed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\nignore\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, the entire transformation will be stopped and no further processing will occur.\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, has the same effect as the ignore flag of stopping the entire transformation, with an error message.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\nvar info = \"Starting Import Set Transformation Mapping operation using Data source, \" \n+ map.table_source + \" and Transform Map \" + map.name + \" on import set \" + import_set.number;\nlog.info( info ); \n\n```\n\n</td></tr><tr><td>\n\nonComplete\n\n</td><td>\n\nWhen: The onComplete event script is processed at the end of an import run, after all data rows are read and transformed.\n\n <table id=\"table_hln_4ss_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onComplete import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe last row of the source import set table.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe last row of target table.\n\n</td></tr><tr><td>\n\nimport\\_set\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe import set that is currently being transformed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, will mark the current import set status to error after it completes.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\n// Create a myimport_completed event that can be reacted by an email notification or script action\n// (there is already an import.finished event that the system will create at the end of an import)\nvar e = new GlideEvent(\"myimport_completed\", import_set.sys_id, map.sys_id, \"\");\ne.insert();\n```\n\n</td></tr><tr><td>\n\nonBefore\n\n</td><td>\n\nWhen: The onBefore event script is processed at the start of a row transformation, before the source row is transformed into the target row.\n\n <table id=\"table_myd_kts_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onBefore import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the source table that is currently being processed.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the target table that is currently being processed.\n\n</td></tr><tr><td>\n\nimport\\_set\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe import set that is currently being transformed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\naction\n\n</td><td>\n\nString\n\n</td><td>\n\nAction returns a value of either \"insert\" or \"update\" indicating whether the current target row is about to be created or updated.\n\n</td></tr><tr><td>\n\nignore\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, the current row transformation will be skipped and the remaining rows will be processed.If you have defined an onAfter script, the onAfter script runs for the current row even if the ignore flag is set to true.\n\n</td></tr><tr><td>\n\nstatus\\_message\n\n</td><td>\n\nString\n\n</td><td>\n\nDefines a custom message to be sent in the &lt;status\\_message&gt; XML response.\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, will halt the entire transformation for the current import set, with an error message.\n\n</td></tr><tr><td>\n\nerror\\_message\n\n</td><td>\n\nString\n\n</td><td>\n\nDefines a custom message to be sent in the &lt;error\\_message&gt; XML response.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\nvar name = source.u_name.toString();\nvar info = \"Before the row is transformed, \" + name;\nlog.info( info ); \n \n// Make sure a company name has been provided\nvar company = source.u_company.toString();\nif(company.length == 0 ){\n\tignore = true;\n\tinfo =\"No company name, row ignored! \" + name;\n\tlog.info( info );\n}\n```\n\n</td></tr><tr><td>\n\nonAfter\n\n</td><td>\n\nWhen: The onAfter event script is processed at the end of a row transformation, after the source row has been transformed into the target row and saved.\n\n <table id=\"table_us2_m5s_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onAfter import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the source table that is currently being processed.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the target table that is currently being processed.\n\n</td></tr><tr><td>\n\nimport\\_set\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe import set that is currently being transformed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\naction\n\n</td><td>\n\nString\n\n</td><td>\n\nAction returns a value of either \"insert\" or \"update\" indicating whether the current target row was created or updated.\n\n</td></tr><tr><td>\n\nstatus\\_message\n\n</td><td>\n\nString\n\n</td><td>\n\nDefines a custom message to be sent in the &lt;status\\_message&gt; XML response.\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, will halt the entire transformation for the current import set, with an error message.\n\n</td></tr><tr><td>\n\nerror\\_message\n\n</td><td>\n\nString\n\n</td><td>\n\nDefines a custom message to be sent in the &lt;error\\_message&gt; XML response.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\nif(source.new==\"true\"){\n  gs.include('Cart');var bundle =new GlideRecord('sc_cat_item');\n  bundle.addQuery('name','CONTAINS','comp');\n  bundle.query();\n  if(bundle.next()){\n     var new_comp_cart = new Cart();\n     var cart = new Cart();\n     var item = cart.addItem(bundle);\n     var rc = cart.placeOrder();\n     log.info(rc.number);}}\n```\n\n</td></tr><tr><td>\n\nonForeignInsert\n\n</td><td>\n\nWhen: The onForeignInsert event script is processed at the start of the creation of a related, referenced record, before the record is created.\n\n <table id=\"table_o4c_svs_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onForeignInsert import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the source table that is currently being processed.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the target table that is currently being processed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\naction\n\n</td><td>\n\nString\n\n</td><td>\n\nAction returns a value of either \"insert\" or \"update\" indicating whether the current target row is about to be created or updated.\n\n</td></tr><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nEvaluates to the field name of the target record for which a foreign record that is about to be created.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nString\n\n</td><td>\n\nEvaluates to the display value from the source record for which a foreign record is about to be created.\n\n</td></tr><tr><td>\n\nignore\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, ignores the creation of a new foreign or related record.\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, rejects the entire transformation row, no data is saved for this row.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\n//Create an event.\nvar e = new GlideEvent(\"myimport_ForeignInsert\", action, name, \"\");\ne.insert();\n```\n\n</td></tr><tr><td>\n\nonChoiceCreate\n\n</td><td>\n\nWhen: The onChoiceCreate event script is processed at the start of a choice value creation, before the new choice value is created.\n\n <table id=\"table_t4k_pws_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onChoiceCreate import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the source table that is currently being processed.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the target table that is currently being processed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr><tr><td>\n\naction\n\n</td><td>\n\nString\n\n</td><td>\n\nAction returns a value of either \"insert\" or \"update\" indicating whether the current target row is about to be created or updated.\n\n</td></tr><tr><td>\n\nname\n\n</td><td>\n\nString\n\n</td><td>\n\nEvaluates to the field name of the target record for which a choice value is about to be created.\n\n</td></tr><tr><td>\n\nvalue\n\n</td><td>\n\nString\n\n</td><td>\n\nEvaluates to the display value from the source record for which a choice is about to be created.\n\n</td></tr><tr><td>\n\nignore\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, ignores the creation of a choice value.\n\n</td></tr><tr><td>\n\nerror\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nWhen set to true, rejects the entire transformation row, no data is saved for this row.\n\n</td></tr></tbody>\n</table> Example:\n\n ```\n//Create an event\nvar e = new GlideEvent(\"myimport_ChoiceCreate\", action, value, \"\");\ne.insert();\n```\n\n</td></tr><tr><td>\n\nonReject\n\n</td><td>\n\nWhen: The onReject event script is processed during the occurrence of a foreign record or choice creation, and the foreign record or choice is rejected ,the entire transformation row is not saved.\n\n <table id=\"table_q5k_4xs_sq\"><thead><tr><th>\n\nImport Set JS object\n\n</th><th>\n\nType\n\n</th><th>\n\nContext in the onError import set event\n\n</th></tr></thead><tbody><tr><td>\n\nsource\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the source table that is currently being processed.\n\n</td></tr><tr><td>\n\ntarget\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nThe row of the target table that is currently being processed.\n\n</td></tr><tr><td>\n\nmap\n\n</td><td>\n\nGlideTransformMap\n\n</td><td>\n\nRead-only information about the current transform map record.\n\n</td></tr><tr><td>\n\naction\n\n</td><td>\n\nString\n\n</td><td>\n\nAction returns a value of either \"insert\" or \"update\" indicating whether the current target row is about to be created or updated.\n\n</td></tr><tr><td>\n\nlog\n\n</td><td>\n\nFunction\n\n</td><td>\n\nThe log object for the current import run. For example, log.info\\(...\\), log.warn\\(...\\), log.error\\(...\\).**Note:** To view the import logs, set the **glide.importlog.log\\_to\\_table** property to true. For more information, see [Import sets properties](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/system-import-sets/r_ImportSetsProperties.md).\n\n</td></tr></tbody>\n</table> Example:\n\n```\n//Create an event\nvar e = new GlideEvent(\"myimport_onReject\", action, \"\", \"\");\ne.insert();\n```\n\n</td></tr></tbody>\n</table>"}}