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

Please Note, do not copy this code and try to run it as is.   Re-write the code to meet your needs.   Some of this is actual code, some of this is random gibberish to give you the idea.



(function(importSet) {


var gr = new GlideRecord('<import_table>');


gr.addQuery('sys_import_set', importSet.sys_id);


              gr.addQUery("WHATEVER RECORDS FROM IMPORT YOU WANT TO ADD A COMMENT TO");


gr.query();


while (gr.next()) {


var targetGR = new GlideRecord(<target table>);


                              if (targetGR.get(gr.sys_target_sys_id)) {


                                        targetGR.u_work_notes = 'MY WORK NOTE';


                                        targetGR.update();


                              }



}


})(import_set);


I Have tried using this




(function(importSet) {


var gr = new GlideRecord('u_current_update');//custom imported table table


gr.addQuery('sys_import_set', importSet.sys_id);


              gr.addQUery(current.state == 'Updated');// to fetch the updated records from the import set


gr.query();


while (gr.next()) {


var targetGR = new GlideRecord('alm_asset');


                              if (targetGR.get(gr.sys_target_sys_id)) {


                                        targetGR.u_work_notes = 'Updated today';// to update work notes


                                        targetGR.update();


                              }



}


})(import_set);




Can you let me know if this need any more changes, as its not updating using the ablove code



thanks,


You copied my mistake, capital u in the 4th line.   I don't see anything else wrong.


Hi Chris,



I have used the same,



But still it is not updating



I am not sure, what else can we do to achieve the same?




thanks,


kamal


Then at this point what you need to do is start adding log statements.



log that you are in the function, log the row count for the query, log the sys_id that you are trying to get with each record you are looping through.   Basically step by step logging so you can see exactly what is happening, just like you could if you were able to step through the code line by line.