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 01:23 AM
Do you need to have any BR's or such running on the case table?
If you add setWorkflow(false) into it, then it skips a lot of extra checks in the case table and might run a lot faster even as a onAfter script. If there are BR's, workflows or other background stuff that needs to run because of this update, then you can't use that.
You can give it a try by adding it to the while loop:
while(orMap.next()){
orMap.setWorkflow(false);
orMap.u_location = loc;
orMap.u_job_code = jobCode;
orMap.update();
}
To run the whole thing as onComplete script, you'd need to query the import set table for each record in the current import set (related rows are in a set) and then use a while loop in there to get all the source data and then a while loop there to update the related cases.
This might be slightly faster than if it run as onAfter, but quite a hefty job still.