- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 04:56 AM
※This is the Paris version.
I learned the basic usage in the following thread.
How to use "Schedule Once" - Service Management - Question - ServiceNow Community
It seems that an error occurs when the function you want to schedule is calling another function as shown below.
How can I resolve this case?
function script2(argument2){
gs.info(argument2);
}
function script(argument){
//ScheduleJob
gs.info(argument);
script2(argument + "~part2");
}
var argument ="Test OK";
var sched = new ScheduleOnce();
sched.script = '('+script+')("'+argument+'");';
sched.schedule();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:22 AM
Hi,
Scheduler does not know the script declared outside. You need to either define the second function inside the first function or create it in script include and refer it.
Refer sample code for first option:
function script(argument){
//ScheduleJob
gs.info(argument);
script2(argument + "~part2");
function script2(argument2){
gs.info(argument2);
}
}
var argument ="Test OK";
var sched = new ScheduleOnce();
sched.script = '('+script+')("'+argument+'");';
sched.schedule();
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:22 AM
Hi,
Scheduler does not know the script declared outside. You need to either define the second function inside the first function or create it in script include and refer it.
Refer sample code for first option:
function script(argument){
//ScheduleJob
gs.info(argument);
script2(argument + "~part2");
function script2(argument2){
gs.info(argument2);
}
}
var argument ="Test OK";
var sched = new ScheduleOnce();
sched.script = '('+script+')("'+argument+'");';
sched.schedule();
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:32 AM
Did you define the function inside the function !!
I was shocked because I didn't know.
This seems to solve various problems.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 05:54 AM
Yes, I defined function inside a function. This is working fine in my instance as well.
Please note that those functions are not accessible outside this function. If you want your function to be called from multiple places then it is preferred to create it in Script Include.
Thank you,
Palani
Palani