109 views

Description

During your troubleshooting, you may want to execute a piece of code as the system user. The schedule worker threads are the system user.

  • Configure the code below with whatever script in the "script" variable for the system to execute
  • Don't forget to escape special characters
  • In the addSecond method, you can define when the script should execute, set to one second to execute immediately¬†
  • Then run the code below in /sys.scripts.do.
  • This will create a [sys_trigger] record for the scheduler worker to pick up.
  • Define variable gr with what you'll want "current" to be in the script defined in the "script" variable.

Instructions


//get the gr of whatever record you want current to be on the script 
var gr = new GlideRecord("sc_req_item");
gr.get("aeed229047801200e0ef563dbb9a71c2");     

//execute one second after running this script
var gdt = new GlideDateTime();
gdt. addSeconds(1)
gs.info(gdt);

//define the script you want to run, in this example it's the stack trace, and don't forget to escape special charectors
var script = "gs.log('***** DEBUG - op:'+ current.operation() + ', sess:' + gs.getSessionID() + ', time:' + new Date().getTime() + ', sys_id:' + current.sys_id + ' - \\n' + GlideLog.getStackTrace(new Packages.java.lang.Throwable()), 'Stacktrace Debug');";

//create the sys_trigger record to be executed by the schedule worker thread
var sched = new ScheduleOnce();
sched.script = script;
sched.setTime(gdt);
sched.setDocument(gr);
sched.setLabel("run this as system");
sched.schedule();

Article Information

Last Updated:2020-05-14 15:59:04
Published:2020-05-14