- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 03:37 AM
Is it possible to programmatically trigger or execute a scheduled script using another script in Servicenow
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 07:23 AM
yes it's possible
var schImp_GR = new GlideRecord('sysauto');
schImp_GR.addQuery('name','<name>'); // Name of the scheduled job
schImp_GR.query();
if(schImp_GR.next()){
SncTriggerSynchronizer.executeNow(schImp_GR); // this is for global scope
gs.executeNow(schImp_GR); // this is for scoped app
}
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
12-12-2023 07:28 AM - edited 12-12-2023 07:29 AM
Hi @snowPankaj ,
Yes , it is possible
Scheduled jobs are an extremely useful way to automate processes in Service-now.com and lift some of the administrative burden of the tool off of the shoulders of your Service-now administrators. It’s very easy to create a scheduled job or a scheduled import. Typically there’s no scripting or advanced configuration involved at all. Just set it up with a schedule and let it run! There are some situations where you might need to execute a scheduled job outside of its normal schedule. You can always open up the scheduled job entry and click the ‘Execute Now’ button, but there are also probably times where you’d really like to automate the process based on some trigger in a workflow or state change in some ticket or CI.
To do this, you simply mimic the behavior of the ‘Execute Now’ button by querying for the scheduled job you want to execute and firing off the job. Here’s the script…
You can modify the script below by adding your scheduled job name and querying the appropriate table for your scheduled job as shown here. This will not work if you simply query the ‘sysauto’ table. You must query one of the extensions below directly.
- ‘scheduled_import_set’ (Scheduled Import Sets)
- ‘sysauto_script’ (Scheduled Script Execution)
- ‘sysauto_template’ (Scheduled Template Generation)
- ‘sysauto_report’ (Scheduled Report)
//Execute a scheduled script job
var rec = new GlideRecord('sysauto_script');
rec.get('name', 'YOUR_JOB_NAME_HERE');
if (typeof SncTriggerSynchronizer != 'undefined')
SncTriggerSynchronizer.executeNow(rec);
else
Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);
Please mark ✅ Correct if this resolves your issue, and also mark 👍 Helpful if you find my response valuable based on its impact.
Regards,
Astik Thombare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 07:23 AM
yes it's possible
var schImp_GR = new GlideRecord('sysauto');
schImp_GR.addQuery('name','<name>'); // Name of the scheduled job
schImp_GR.query();
if(schImp_GR.next()){
SncTriggerSynchronizer.executeNow(schImp_GR); // this is for global scope
gs.executeNow(schImp_GR); // this is for scoped app
}
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
12-12-2023 07:28 AM - edited 12-12-2023 07:29 AM
Hi @snowPankaj ,
Yes , it is possible
Scheduled jobs are an extremely useful way to automate processes in Service-now.com and lift some of the administrative burden of the tool off of the shoulders of your Service-now administrators. It’s very easy to create a scheduled job or a scheduled import. Typically there’s no scripting or advanced configuration involved at all. Just set it up with a schedule and let it run! There are some situations where you might need to execute a scheduled job outside of its normal schedule. You can always open up the scheduled job entry and click the ‘Execute Now’ button, but there are also probably times where you’d really like to automate the process based on some trigger in a workflow or state change in some ticket or CI.
To do this, you simply mimic the behavior of the ‘Execute Now’ button by querying for the scheduled job you want to execute and firing off the job. Here’s the script…
You can modify the script below by adding your scheduled job name and querying the appropriate table for your scheduled job as shown here. This will not work if you simply query the ‘sysauto’ table. You must query one of the extensions below directly.
- ‘scheduled_import_set’ (Scheduled Import Sets)
- ‘sysauto_script’ (Scheduled Script Execution)
- ‘sysauto_template’ (Scheduled Template Generation)
- ‘sysauto_report’ (Scheduled Report)
//Execute a scheduled script job
var rec = new GlideRecord('sysauto_script');
rec.get('name', 'YOUR_JOB_NAME_HERE');
if (typeof SncTriggerSynchronizer != 'undefined')
SncTriggerSynchronizer.executeNow(rec);
else
Packages.com.snc.automation.TriggerSynchronizer.executeNow(rec);
Please mark ✅ Correct if this resolves your issue, and also mark 👍 Helpful if you find my response valuable based on its impact.
Regards,
Astik Thombare