Transform script log update

rog
Giga Contributor

Hi,

I need help with the transform script logs. Currently I am updating a bulk of assets and I need to put in logs to check.

I need logs to check which assets have been updated and which assets have not been updated in the transform.

Any suggestions are welcome.

ty.

14 REPLIES 14

karthik73
Mega Guru

Hi Roger,



Yes, that is right. I guess you should be able make the log conditional based on insert/update. ServiceNow Wiki suggests action should say insert/update . I haven't tried this option before, may be you can try if 'action' serves your purpose.


rog
Giga Contributor

Hi Karthik,



I didn't quite get that. Can you help me provide a script for the same, that would be helpful



Thanks.


Hi Roger,



You can add the script under the transformation map itself (check the run script check box),



Here is the sample script I created to log insert/update, you can tweak that to your need. I think its better to make use of the transformation specific logging, instead of the generic logs.



(function transformRow(source, target, map, log, isUpdate) {




if(action == "insert"){


  // writes to the generic log


  gs.log('target row inserted' + target.u_number);


  // writes to the log with the source details   (easier to find)


  log.info('target row inserted123'+ target.u_name);


}


  else if(action == "update"){


  // writes to the generic log


  gs.log('target row updated' + target.u_number);


  // writes to the log with the source details   (easier to find)


  log.info('target row updated456'+ target.u_name);


}




})(source, target, map, log, action==="update");


rog
Giga Contributor

Hi Karthik,



Thanks for the help. But the logs are updating for all the assets even for the assets that have not been updated.


Hi rog and @karthik do you guys have an update on this? I am also receiving "update" value on the action variable even if the there is no record to update and records are non-existent on the target table. Kindly help...