Business rule is not working when unchecked the Run Business rule from the transform Map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2023 03:50 AM - edited 07-28-2023 05:02 AM
Hi,
I have noticed that once i have disabled the Run Business Rule checkbox from transform map, any business rule written on the targeted table is not running.
Below is the business rule-
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord("sn_hr_core_case");
gr.addQuery("u_order_number",current.u_order_number);
gr.query();
while (gr.next()) {
gr.u_location=current.u_location;
gr.u_job_code=current.u_job_code;
gr.update();
gr.setWorkflow(false);
}
})(current, previous);
Whenever a order number/loc/code is inserted or updated via a data load, BR is not working
@Ankur Bawiskar :could you please help...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 04:26 AM
@Ankur Bawiskar : the target table is a custom table- Order mapping and based on some fields of custom table, need to check in hr case table and update the value according.
the excel file will contain around 12k records daily. So i have unchecked the run Business rule( as it was taking much time to load data), so i have written a onAfter script, but still the latency is there
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var orMap = new GlideRecord('sn_hr_core_case');
orMap.addEncodedQuery('active=true^u_order_numberISNOTEMPTY^u_order_number=' + source.u_order_id);
orMap.query();
while (orMap.next()) {
orMap.u_location = source.u_location;
orMap.u_job_code = source.u_job_code;
}
if (orMap.getRowCount() > 0) {
orMap.setWorkflow(false);
orMap.updateMultiple();
}
})(source, map, log, target);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 04:53 AM
3 hours for 3K record is like hardly 3-4 seconds per record which I believe is normal for this Script. So this should be expected behavior.
Also can optimize script with proper Query:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var orMap = new GlideRecord('sn_hr_core_case');
orMap.addEncodedQuery('active=true^u_order_number=' + source.u_order_id);
orMap.query();
if(orMap.next()) { // Asssuming there would be only 1 record with each Order Number
orMap.u_location = source.u_location;
orMap.u_job_code = source.u_job_code;
orMap.setWorkflow(false);
orMap.update();
}
})(source, map, log, target);
Use If condition if GlideRecord returns only 1 record else can use While. Rest of the script would be same. Hope this will reduce the time to some extend.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:08 AM
I would still recommend using BR and keep the checkbox of Run business rule active on transform map.
12k records daily should still be fine and you can ensure that the data load happens during off-business hours
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:29 AM
Hi @Ankur Bawiskar, keeping the run business rule as checked is again causing the issue, it will take much time to load around 4-5 hrs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 05:58 AM
it will anyhow impact.
Even if BR is running it will take time
Even if you are using oAfter it will take time to complete the entire load.
So that's the reason I mentioned it's better to run this during off-business hours
Please discuss this with your customer.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader