- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 10:31 PM
Hello Everyone,
I have a requirement like I need to trigger 5 scheduled jobs from UI Action(List Banner Button) script.
For that I have written the script, but the issue i am facing is the while loop is taking only one sys_id from among the 5 scheduled jobs sys_ids.
Please need a suggestion on this to trigger all the queried sys_ids
UI Action Script :
runScript();
function runScript() {
var gr = new GlideRecord('sysauto_script');
gr.addEncodedQuery('sys_idIN690f3396db61d014b4dbb5b9689619f7,b7c91c1cdbad5850ae12ebd848961961,5f4f9f93db559810ae12ebd8489619a7,f701102fdb51d810ae12ebd8489619b6,1a9199abdb511c10ae12ebd84896199d');
gr.query();
while (gr.next()) {
SncTriggerSynchronizer.executeNow(gr);
}
}
Thanks & Regards
Ramananth
Solved! Go to Solution.
- Labels:
-
Project Portfolio Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 03:13 AM
Hi,
nope
1 event, 1 script action
for event - don't give any table
Note: this is just an assumption that the job would complete in 5mins as there is dependency between those jobs; you give approx your time
Sample UI action script:
Note: Ensure you give valid scheduled job sys_id in the parameter
runScript();
function runScript() {
// for 1st job
var gdt = new GlideDateTime();
gdt.addSeconds(300);
gs.eventQueueScheduled("your_event_name", '', job1SysId ,gs.getUserName(),gdt);
// for 2nd job
var gdt = new GlideDateTime();
gdt.addSeconds(600);
gs.eventQueueScheduled("your_event_name", '', job2SysId ,gs.getUserName(),gdt);
// for 3rd job
var gdt = new GlideDateTime();
gdt.addSeconds(900);
gs.eventQueueScheduled("your_event_name", '', job3SysId ,gs.getUserName(),gdt);
// for 4th job
var gdt = new GlideDateTime();
gdt.addSeconds(1200);
gs.eventQueueScheduled("your_event_name", '', job4SysId ,gs.getUserName(),gdt);
// for 5th job
var gdt = new GlideDateTime();
gdt.addSeconds(1500);
gs.eventQueueScheduled("your_event_name", '', job5SysId ,gs.getUserName(),gdt);
}
Sample Script Action Script
var jobSysId = event.parm1; // this gives you job sys_id sent when event triggered
var gr = new GlideRecord('sysauto_script');
gr.addQuery('sys_id', jobSysId);
gr.query();
if(gr.next()) {
SncTriggerSynchronizer.executeNow(gr);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 02:44 AM
Hi Ankur,
Thanks, your suggestion is good. But the i need some guidance to achieve this.
With respect to my requirement:
1) I need to create 5 events? and 5 Script Actions? for 5 Scheduled jobs.
2) You said that somewhere we have to give the order of executing the scheduled job and the time 5 minutes, where?
Please suggest me a brief idea on this.
Thanks in Advance
Ramananth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 03:13 AM
Hi,
nope
1 event, 1 script action
for event - don't give any table
Note: this is just an assumption that the job would complete in 5mins as there is dependency between those jobs; you give approx your time
Sample UI action script:
Note: Ensure you give valid scheduled job sys_id in the parameter
runScript();
function runScript() {
// for 1st job
var gdt = new GlideDateTime();
gdt.addSeconds(300);
gs.eventQueueScheduled("your_event_name", '', job1SysId ,gs.getUserName(),gdt);
// for 2nd job
var gdt = new GlideDateTime();
gdt.addSeconds(600);
gs.eventQueueScheduled("your_event_name", '', job2SysId ,gs.getUserName(),gdt);
// for 3rd job
var gdt = new GlideDateTime();
gdt.addSeconds(900);
gs.eventQueueScheduled("your_event_name", '', job3SysId ,gs.getUserName(),gdt);
// for 4th job
var gdt = new GlideDateTime();
gdt.addSeconds(1200);
gs.eventQueueScheduled("your_event_name", '', job4SysId ,gs.getUserName(),gdt);
// for 5th job
var gdt = new GlideDateTime();
gdt.addSeconds(1500);
gs.eventQueueScheduled("your_event_name", '', job5SysId ,gs.getUserName(),gdt);
}
Sample Script Action Script
var jobSysId = event.parm1; // this gives you job sys_id sent when event triggered
var gr = new GlideRecord('sysauto_script');
gr.addQuery('sys_id', jobSysId);
gr.query();
if(gr.next()) {
SncTriggerSynchronizer.executeNow(gr);
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:26 AM
Hi Ankur,
Thankyou for your sample script and suggestion.
I will work on this.
Thanks,
Ramananth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 06:36 AM
Do let us know
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 04:09 AM
Hope you are doing good.
If you find my response solved your issue, please mark answer as Correct & Helpful to help others with the same response find the answer more quickly
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader