SncTriggerSynchronizer.executeNow() is not working on background script

jordimsant
Tera Guru

I am trying to launch scheduled job from Background Script and it does not work. The script I am using is

var gr_micro = new GlideRecord('sysauto');
gr_micro.get('93bbb322871e521024530fa90cbb3524');
SncTriggerSynchronizer.executeNow(gr_micro);

The error that I am getting is shown in the following image:

jordimsant_0-1736318480038.png

Can anybody help me? I have checked that the sys_id is correct, so the record is correctly found.

 

1 ACCEPTED SOLUTION

Ravi Gaurav
Giga Sage
Giga Sage

Hi @jordimsant 

Ensure you are logged in as a user with the admin role and that the instance allows background script execution of such operations.
correct format :-

var gr_micro = new GlideRecord('sysauto');
if (gr_micro.get('93bbb322871e521024530fa90cbb3524')) {

if (gr_micro.active) {
gs.print("Found scheduled job. Executing now...");
SncTriggerSynchronizer.executeNow(gr_micro);
} else {
gs.print("Scheduled job is inactive. Activate it before execution.");
}
} else {
gs.print("Scheduled job not found.");
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

View solution in original post

3 REPLIES 3

Ravi Gaurav
Giga Sage
Giga Sage

Hi @jordimsant 

Ensure you are logged in as a user with the admin role and that the instance allows background script execution of such operations.
correct format :-

var gr_micro = new GlideRecord('sysauto');
if (gr_micro.get('93bbb322871e521024530fa90cbb3524')) {

if (gr_micro.active) {
gs.print("Found scheduled job. Executing now...");
SncTriggerSynchronizer.executeNow(gr_micro);
} else {
gs.print("Scheduled job is inactive. Activate it before execution.");
}
} else {
gs.print("Scheduled job not found.");
}

 

--------------------------------------------------------------------------------------------------------------------------


If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!

Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI

 YouTube: https://www.youtube.com/@learnservicenowwithravi
 LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/

Thank you for your help! The problem was the "Run as" field, I suppose that the previous user has not the rights to execute the script

Shruti
Mega Sage
Mega Sage
var gr_micro = new GlideRecord('sysauto_script');
gr_micro.get('93bbb322871e521024530fa90cbb3524');
SncTriggerSynchronizer.executeNow(gr_micro);