Delay creation of records in for loop of business rules

Sriharsha Radha
Tera Contributor

Hello,

 

I have an async business rule which splits an array from a field and creates multiple records according to array length using for loop.

This is working fine. However, records are inserted at once without any delay. I wanted these inserts to be delayed atleast by 20 seconds as there are transform maps in the background which should assess whether to push these inserted records into a target table or update it. Since, there is no delay, all are being pushed as new insert on target table causing issues in data.

 

How can we add delay after for loop for these record inserts to take some time?

1 ACCEPTED SOLUTION

Since, we are adding delay in the script, there is definitely a performance issue and if this record count is in multiple of thousands then it might take hours to process.

Regarding your main concern that system is inserting record instead of updating, I don't think this issue should exist in the first place. Because, as you must be having coalesce field configured on transform map, even if we have multiple record with same coalesce field(unique id) then once first record is inserted then 2nd, 3rd record executes update operation automatically even if they are part of same import set record. So, not sure how you are facing this issue or I am completely understanding your main concern.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

3 REPLIES 3

Abhijit4
Mega Sage

Hello,

You can use gs.sleep(20000) after gr.insert() statement so that it will wait for 20 seconds after creating each record.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Doesnt this cause performance issues as these array records are created in quick succession causing same business rule to run at a time in few cases. 

Since, we are adding delay in the script, there is definitely a performance issue and if this record count is in multiple of thousands then it might take hours to process.

Regarding your main concern that system is inserting record instead of updating, I don't think this issue should exist in the first place. Because, as you must be having coalesce field configured on transform map, even if we have multiple record with same coalesce field(unique id) then once first record is inserted then 2nd, 3rd record executes update operation automatically even if they are part of same import set record. So, not sure how you are facing this issue or I am completely understanding your main concern.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP