- 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 07:49 PM
is your instance slow because sometimes schedule job takes time to run as system will pick it based on queue mechanism?
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-27-2025 06:16 AM
No, there's nothing else running on the instance. I did finally get it to work.
This is my final code snippet -- I just needed to return the answer after the last curly bracket.
answer = false;
var gdt = new Date();
var day = gdt.getDay();
if(day != 0 && day != 2 && day != 3 && day != 5 && day != 6) {
answer = true;
}
answer;
runJob();
function runJob(){
try {
var result = sn_fd.FlowAPI
.getRunner()
.subflow('global.approval_reminder')
.inBackground()
.run();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
}
Your suggestion of the function helped. I will mark yours as the solution. Thanks!