Automate killing of long running scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:21 AM
Hi all,
We have a requirement from customer that if scheduled Job is running for more than an hour , it should be stopped automatically.
Is there any way to automate this procedure ? if so, where can we add the required steps ?
Thanks,
PG.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:22 AM
Hi @Pratima G
https://www.servicenow.com/community/developer-forum/kill-the-scheduled-job/m-p/1989129
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:32 AM
Hey Atulya,
Thank for the links.
However if I want to automate this code , how can I do it ? I tried with a flow designer but i could not find any element which connects from executed scheduled job and the active transaction table.
How can we query a particular scheduled job transaction in Active Transactions ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:40 AM
Hi @Pratima G
Sorry I am not a pro here, may be you can see:
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 03:40 AM
HI @Pratima G ,
I trust you are doing great.
Please find the code as given below
var gr = new GlideRecord('sys_trigger');
gr.addQuery('next_action', '<', 'javascript:gs.minutesAgo(60)');
gr.addEncodedQuery('state=0^name= Reminder CDB datapurge admin^next_action<javascript:gs.beginningOfCurrentHour()');
gr.query();
while (gr.next()) {
// Logic to determine if the job is still running and needs to be stopped
// Implement your stopping mechanism here
// Log or notify
gs.info('Job ' + gr.name + ' has been running for more than an hour and was stopped.');
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi