How to trigger script action from scheduled job using gs.eventQueueScheduled() [delay is 10 min]

Obito
Tera Expert

Hi all,

How to trigger script action from scheduled job using gs.eventQueueScheduled() where delay is 10 min. We have scheduled job which runs daily so 10 min after triggering the schedule job we  want to create one record which we are doing through script action. What object I should passed in gs.eventQueueScheduled(); as we can not pass current.

 

Thanks

5 REPLIES 5

Shaqeel
Mega Sage

Hi @Obito 

 

Sure, here are the steps to trigger a script action from a scheduled job using gs.eventQueueScheduled() with a delay of 10 minutes:

 

1. First, create a Script Action. Navigate to System Policy > Script Actions. Click on New to create a new script action.

- Name: Give it a name (e.g., "My Script Action").

- Table: Choose the table you want this script action to run on.

- Active: Make sure it's active.

- Action: Choose "Event Fired".

- Event Name: Give it an event name (e.g., "custom.event").

 

2. In the Script field, write the script you want to execute when the event is fired.

 

3. Now, create a Scheduled Job. Navigate to System Definition > Scheduled Jobs. Click on New to create a new scheduled job.

- Name: Give it a name (e.g., "My Scheduled Job").

- Active: Make sure it's active.

- Run: Choose when you want this job to run.

 

4. In the Script field, write the following script to trigger the event with a delay of 10 minutes:

javascript

var gdt = new GlideDateTime();

gdt.addSeconds(600); // 600 seconds = 10 minutes

gs.eventQueueScheduled("custom.event", current, "parameter1", "parameter2", gdt);

 

In this script:

- "custom.event" is the name of the event you created in the script action.

- current is the current record.

- "parameter1" and "parameter2" are optional parameters you can pass to the event.

- gdt is the time when you want the event to be fired.

 

5. Save the scheduled job.

 

Now, the scheduled job will trigger the script action with a delay of 10 minutes.

 

Mark Helpful/Solution 🙂

 

Regards

Shaqeel


***********************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful." This action benefits both the community and me.

***********************************************************************************************************************





Regards

Shaqeel

Thank you for the reply, May I know what object to use other than 'current' while calling gs.eventQueueScheduled("custom.event", current, "parameter1", "parameter2", gdt); 

As I can not use current in scheduled job. I tried using 'null' ,it throws error

Harsh Vardhan
Giga Patron

@Obito  If you have not any object ( eg: current ) then you can pass blank value in eventQueueScheduled() parameter

 

eg:  gs.eventQueueScheduled("<yourEventName>","","","", dt);  // make changes based on your need in parameter value. 

 

Thanks,

Harsh

Thanks Harsh for quick reply, let me check if it works.