- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 08:52 PM
※Paris version
※I'm sorry for being persistent.
I felt that I could get a rough idea of how to use "Schedule Once" and its features in the thread below.
https://community.servicenow.com/community?id=community_question&sys_id=bac79caedb490d14da1999ead396199b
https://community.servicenow.com/community?id=community_question&sys_id=013f0d66db45c190382a82630596198a
However, there is one part that I still don't understand.
What does "sched.script =" in the code below mean?
I can't figure out what I'm doing here because I can't find a function named "script" in "Schedule Once".
function script(argument){
//ScheduleJob
gs.info(argument);
}
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-18-2022 04:29 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 04:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 04:33 AM
Thank you!
I deepened my understanding!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 07:26 AM
Hi Hitoshi,
I am trying to schedule a function that belongs to the same class using your method, but It does not seem to work.
var scheduleTest = Class.create();
scheduleTest .prototype = {
initialize: function(addButton) {
gs.debug("User in initialize funciton: " + gs.getUser());
this.addButton = addButton
},
debugLog: function(){
gs.debug("Schedule executed");
},
mySchedule: function(){
gs.debug("scheduleTest reached");
var argument ="Schedule test";
var gdt = new GlideDateTime();
gdt.addSeconds(1);
var sched = new global.ScheduleOnce();
sched.script = '('+debugLog+')("'+argument+'");';
sched.setTime(gdt);
sched.setLabel("run this as system");
sched.schedule();
},
type: 'scheduleTest '
};
scheduleTest() is called from another script include. scheduleTest() executes fine (I can see the debug message in Session Logs) but it does not call schedTest(). I am not sure what I'm doing wrong here. Any help would be appreciated.
Thanks,
T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 06:55 AM
Hi Hitoshi,
I am trying to schedule a function using your method, but it doesn't work for me. Could you help me and tell me what I am doing wrong in my code? runSchedule function is called by another script - I know the call is successful because I can see the debug message in Session Log.
var scheduleTest = Class.create();
scheduleTest.prototype = {
initialize: function(addButton) {
gs.debug("User in initialize function: " + gs.getUser());
},
testFunction: function(){
gs.debug("Test function executed");
},
runSchedule: function(){
var argument ="Schedule executed";
var sched = new global.ScheduleOnce();
sched.script = '('+testFunction+')("'+argument+'");';
gs.debug("Schedule reached");
sched.schedule();
},
type: 'scheduleTest'
};
Thanks in advance,
T.