Issue with "onAfter" script with in transform map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2017 12:09 PM
Hi All,
We are facing an issue with the onafter script that we use in transform.
we are trying to bulk update the Records and we want the records which have been updated to update "work-notes" as well.
We have used the following code
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
if(action == "update")
target.u_work_notes = "The Ordered fields of the asset have been updated as per STRY##";
gs.log('The asset with the following serial number is updated: ' + target.serial_number);
})(source, map, log, target);
How ever
it isnt updating the record worknotes
Please let us know if we have to correct something on the same.
Thank you,
Kamal
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 07:13 AM
Oh sorry, it's also not current.state
gr.addQuery('sys_import_state', 'updated');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2020 06:50 AM
To echo what other people have said, by the time the onAfter script runs, the record has already been saved to the database. So it's too late to modify the "target" record.
If you want to set the Work Notes field (whether it's work_notes or u_work_notes), that needs doing before the record is updated in the database. Options:
- Do it instead in an onBefore transform map script
- Have a field map script for the Work Notes field, and put the code in that field map script
- Or do in the main transform map script, that you see if you check the "Run script" check box on the transform map.
Any of those would work, and in any of them the transform will know whether it's an update or an insert, so the check on action == "update" will work. I'd say the best/correct place would be #2.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2020 02:48 PM
The nice thing about #2 is that the individual field map scripts are basically designed so that you just return the value you want set in the target. It's clean. (Something weird is that you don't get the "syntax highlighting" in the Source Script field; I have no idea why that would be; so it feels like you are writing script in Notepad.)
One issue I had with option #1 is that if you modify the Source fields, are are actually permanently modifying the data in your Staging table. This could be confusing to someone looking back at that data, or could trip you up if you "Reprocess" the records (set them to Pending and do multiple Transforms) because you will not be starting from the same point as when you first loaded the records.