- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 09:19 AM - edited 03-26-2025 09:53 AM
Hello ServiceNow Community!
I am trying to trigger a subflow on my scheduled job that's supposed to run Mondays & Wednesdays. Here is my condition:
answer = false;
var gdt = new Date();
var day = gdt.getDay();
if(day != 0 && day != 2 && day != 4 && day != 5 && day != 6) {
answer = true;
}
This works fine because when I use gs.info, day 3 returns today and answer is in fact true.
My script to execute is as follows:
(function() {
try {
var result = sn_fd.FlowAPI
.getRunner()
.subflow('global.approval_reminder')
.inForeground()
.run();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
When I execute this job, the subflow is not being triggered. What am I doing incorrectly?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 10:09 AM
don't use self invoking function, simply use normal function
runJob();
function runJob(){
// your code
}
Did you try running your script in background script and see if subflow is getting triggered?
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
03-26-2025 09:24 AM
did you add gs.info() and see in that script?
this didn't come?
gs.info('nb did this run?');
Did you test your subflow actually works and no error is thrown?
try to check this
(function() {
try {
gs.info('Before triggering subflow');
var result = sn_fd.FlowAPI
.getRunner()
.subflow('global.approval_reminder')
.inForeground()
.run();
gs.info('nb did this run?');
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
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
03-26-2025 09:38 AM - edited 03-26-2025 09:47 AM
Hi @Ankur Bawiskar I did try adding the gs.info in the beginning before triggering the subflow and after the execution and I didn't see 'before triggering subflow' or 'nb did this run?' in the log, which means the script is not being executed. The subflow does work just fine if executed it manually.
What can I do to resolve this? Is my conditional script written incorrectly? I even added gs.info logs in my conditional script:
gs.info('nb - gdt is ' + gdt);
gs.info('nb - day is ' + day);
gs.info('nb - answer is ' + answer);
and these are the results:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 10:09 AM
don't use self invoking function, simply use normal function
runJob();
function runJob(){
// your code
}
Did you try running your script in background script and see if subflow is getting triggered?
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
03-26-2025 10:18 AM
@Ankur Bawiskar I did what you suggested. Here is my new scheduled script:
runJob();
function runJob(){
try {
gs.info('did the script even start?');
var result = sn_fd.FlowAPI
.getRunner()
.subflow('global.approval_reminder')
.inForeground()
.run();
gs.info('did this run?');
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
}
It still did not execute the job.
I did try running this exact script using a Background Script and it works flawlessly using a background script.
I am not sure why it won't execute in my scheduled job.