Is it possible to pass parameters to the scheduled job?

Flavio Tiezzi
Kilo Sage

Hello everyone,

 

I need to execute a script that inserts into the sys_user_grmember table. However, since the Application Administration is active, I need to run it with the admin user of the application. I tried running it via Scheduled Job with this user, and it worked well, but I can't seem to update the parameters.

 

PS: I am aware of SncTriggerSynchronizer but not sure how to pass the parameter.

 

Does anyone have any suggestions?

 

 

Thanks.

1 ACCEPTED SOLUTION

Flavio Tiezzi
Kilo Sage

To solve my issue, I created a new role with the Application Administration field set to true and assigned this role to the user who needed to run the scripts. This allowed the script to be executed.

View solution in original post

8 REPLIES 8

Kris Moncada
Tera Guru

I would recommend the use of a Script Action because it allows you to execute long running jobs in the background (longer that 5mins) and pass parameters to it. 

 

  1. Create an event in the Event Registry. 
    KrisMoncada_0-1717564454459.png

     

  2. Create a Script Action. Notice here I am binding it to the event we created earlier.KrisMoncada_1-1717564532318.png

     

  3. Execute the Script Action. For this example I am using a Fix Script, but you can use a Business Rule, Scheduled Job, another Script Action, etc...
    KrisMoncada_2-1717564683329.png

     

  4. Here's the result:
    KrisMoncada_3-1717564796716.png

     

Hope this inspires new ideas on what you can do.

Thanks for your input.

 

But in this case, the action will be executed by the system user, right? The issue in my case is that I need the action to be executed with a specific user

 

You can leverage GlideImpersonate; documentation located here.

 

//pulled straight from the documentation

var user = gs.getUserDisplayName();
gs.print ("The current user display name is: " + user);

var impUser = new GlideImpersonate();
impUser.impersonate("62826bf03710200044e0bfc8bcbe5df1");
var user = gs.getUserDisplayName();
gs.print ("The impersonated user display name is: " + user);

 

 

I have leveraged GlideImpersonate on a few ServiceNow to JIRA integrations (bi-directional communication), where by a comment added to Jira would appear on the ServiceNow ticket as if the user commented on the ticket.

Kieran Anson
Kilo Patron

Hi,

What do you mean by not being able to update parameters?

Scheduled Jobs aren't intended to have values passed into them, they're intended to be self-invoking and fetch any information they require (potentially from a system property).