The CreatorCon Call for Content is officially open! Get started here.

Issue with "onAfter" script with in transform map.

kamal11
Giga Expert

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

22 REPLIES 22

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


Chris M3
Tera Guru

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.


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.


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.


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