Wait for condition in scheduled job script.

Ajay37
Tera Contributor

Hi,

I am using a schedule job, where I am querying the records from a table and doing some action for the retrieved records. Now I want to have delay between each record to get that action done (one after the other after few seconds). Could anybody has an idea?

Thanks

1 ACCEPTED SOLUTION

Hi Ajay,

Yes, you can use that way. You would need to use it after you write gr.update() statement so that system will keep delay after every update as per your requirement.

Note: Consider delay timing before executing script e.g. If you are updating  1lakh records then keeping 1 seconds delay for each record will take more than 24hours.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

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

12 REPLIES 12

Abhijit already answered how to achieve with a coding solution, using gs.sleep()

do you need additional help?

Abhijit4
Mega Sage

Hi,

You can use gs.sleep(1000) // 1000 is time in ms.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

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

Ajay37
Tera Contributor

Hi @Abhijit ,

Thanks. Is it fine to use gs.sleep() in scheduled job? Can we get any challenges?

Yes, it is absolutely fine to use gs.sleep() in scheduled job. However, it will not work in scoped application.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

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

In case if you would want to use it in scope app then you can follow below kb article, that's easiest and efficient way to achieve it in scope.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0962370

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

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