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 09:10 PM
Hey Kamal,
You can definitely write a BR after update to update your work_notes field.
current.work_notes = "The Ordered fields of the asset have been updated as per STRY##";
current.update();
post me your feedback
Please Hit ✅Correct, âÂ��Helpful, or ��Like depending on the impact of the response
Have a lovely day ahead
Regards,
Divya Mishra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 05:28 AM
Add a target.update() in there. It's a lot like an after business rule, the record has already been saved.
Note also, that may not work, as I'm not sure target is a true GlideRecord. If not, then you will need to re-query for the record using target.sys_id (should be valid), and then do the update.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 05:30 AM
Actually, to add. action == 'update' will come across as true, regardless of whether there were any fields to update. It's basically just saying there is an existing row.
So, if you want to see if it was really updated, you'll have to re-query for the row, and do something with the update date probably to make that determination.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 05:36 AM
Or...
An On Complete script can query against the import table, and look at the Skipped/Updated/Insertted, get the target rows, and make the work note. This is probably the best solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 05:44 AM
HI Chris,
Thanks for the prompt response,
Can you please share a script where in we can query all the updated records to update asset worknotes
Thanks,
Kamal