onComplete script is help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:13 AM
Hi All,
I was creating a onComplete transform script to map the location and code in the HR case if the order number is matched from the excel sheet.
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var loc = source.u_location;
var jobCode = source.u_job_code;
var orderNum = source.u_order_id;
var orMap = new GlideRecord('sn_hr_core_case');
orMap.addEncodedQuery('active=true^u_order_numberISNOTEMPTY');
orMap.addQuery("u_order_number",orderNum);
orMap.query();
while(orMap.next()){
orMap.u_location= loc;
orMap.u_job_code= jobCode;
orMap.update();
}
})(source, map, log, target);
But the onComplete script is not working, please help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:35 AM
Hello @Jyoti Tripathi
I'm afraid that this onComplete transform script won't work.
Instead create a field map and add the script there, so for every record it will check for the orderNum and if found it will update the location and jobcode accordingly.
Please mark this response as correct or helpful if it assisted you with your question.
Regards,
Nitesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 01:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:50 AM
How is it not working? Have you tried logging?
Using onComplete means that it's run at the end after each row has been processed. Using source.field_name there is using the last processed row as reference, so if you've meant to run this for each transform then you need to change it to onAfter.
But your code itself seems OK. Maybe consider combining the encoded query and query to make sure that's not causing issues (it shouldn't, but you can try).
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var loc = source.u_location;
var jobCode = source.u_job_code;
var orderNum = source.u_order_id;
if(orderNum != ''){
var orMap = new GlideRecord('sn_hr_core_case');
orMap.addEncodedQuery('active=true^u_order_number=' + orderNum);
orMap.query();
while(orMap.next()){
orMap.u_location = loc;
orMap.u_job_code = jobCode;
orMap.update();
}
}
})(source, map, log, target);
But to make sure it's running OK, I'd recommend adding logging and checking syslog table to see what it is doing .
For example this would tell you a lot about what is going on:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var loc = source.u_location;
var jobCode = source.u_job_code;
var orderNum = source.u_order_id;
gs.info("Transform run for orderNum: " + orderNum);
if(orderNum != ''){
var orMap = new GlideRecord('sn_hr_core_case');
orMap.addEncodedQuery('active=true^u_order_number=' + orderNum);
orMap.query();
while(orMap.next()){
gs.info("Transform run on case: " + orMap.number + "with values for loc and job:" + loc + " and " + jobCode); //Assuming cases have numbers
orMap.u_location = loc;
orMap.u_job_code = jobCode;
orMap.update();
}
}
})(source, map, log, target);
In the logs you can search for messages starting with "Transform run" and then you'll see which orderNum and case it ran on and if looking at errors you could even see if there was an error running the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 12:55 AM
Hi @Weird : Before my code was written on OnAfter condition, but the data is huge and took around 2 hours to complete the transform mapping. SO was thinking to do it with onComplete.