Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Passing data to Scheduled Script

jcanuel
Kilo Explorer

Hi

I am triggering a Scheduled Script from a UI Action using SncTriggerSynchronizer.executeNow.

Is it possible to pass data to the Scheduled Script ?

Thanks

5 REPLIES 5

sumukh
Kilo Expert

Jacques Canuel - Hi Jack - Were you able to resolve this?



All - Has anyone accomplished this? I want to pass a parameter to scheduled job while triggering it from a script. I am aware of SncTriggerSynchronizer but not sure how to pass the parameter.



Any help will be appreciated.


The SN Nerd
Giga Sage
Giga Sage

Could I suggest that you use an event to trigger a UI Script.


This way you can parse parameters to your script.



  1. Navigate to "System Policy > Events > Registry"
  2. Click 'New'
  3. Create your event record (let's say "event.test")
  4. Add the following code to your Server Side UI Action

    var parm1 = "Whatever you want";
    var parm2 = "Something else";
    gs.eventQueue("event.test", current, parm1, parm2);
  5. Navigate to "System Policy > Events > Script Actions"
  6. Click 'New'
  7. Set event to "event.test"
  8. Write your script in 'Script'
  9. Use variables 'parm1' and 'parm2' to refer to your parameters


Script Actions - ServiceNow Wiki



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Paul Morris - Thanks for your reply. I am aware of this approach. However, I want to run a "scheduled job" with the params. Especially use the feature of running the script as a particular user.


Unfortunately I can't see any other way to do it.


If you want to a script to execute as a user, you could impersonate the user via the gs.getSession().impersonate(parm1), where parm1 is gs.getUserID() from the calling business rule.



If you didn't have a requirement to parse in parameters you could also use



fcRunAs=user


fcScriptName=incident autoclose



to run the the scheduled job as a user, where the script is a business rule.



Closing Resolved Incidents Automatically - ServiceNow Wiki



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022