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 05:58 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 06:12 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 06:26 AM
You copied my mistake, capital u in the 4th line. I don't see anything else wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 06:50 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2017 06:53 AM
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.