Triggering a script action from an event

Ram117
Kilo Sage

Experts,

I have a scoped application OnDemand syauto_script creating a custom event. This scheduled event (gs.eventScheduled : code below) is basically creating a script which kicks a script action

gs.eventQueueScheduled('x_abc_scope.trigger_next_sch', scheduleGr, "trigger_next_job", scheduleGr.getUniqueValue(), gdt);

The script action contains a script which needs to trigger a schedule script execution (sysauto_Script).

When the scheduled event runs, I am not able to see the script action 'script' not getting executed. Below is the script within the script action. The script action is created on the scoped app.

// here parm2 is coming from the event
try {
    gs.info('Trigger next schedule job starting <--');
    var schedGr = new GlideRecord("sysauto_script");
    if (schedGr.get(event.parm2)) {
        gs.executeNow(schedGr);
        gs.info("Triggered for sysauto_script");
    }
} 
catch (ex) {

  throw new Error('Unable to find sysauto_script with sys_id  passed from event '+ex.message);

}

 

sysevent created 

find_real_file.png

 

Thx

ram.

 

1 ACCEPTED SOLUTION

Ram117
Kilo Sage

Closing the thread.

The issue was with my event condition check. As I said, the issue was something silly and now its all working fine.

View solution in original post

14 REPLIES 14

@sachin.namjoshi  , I even added a new record for Table resource (sysauto_Script), no luck yet.. 

I may be missing something silly.

-O-
Kilo Patron
Kilo Patron

Did you make sure the Script Action is active? The default value for Active on Script Actions is false.

Yes, the script action is active

find_real_file.png

-O-
Kilo Patron
Kilo Patron

I have a curiosity: why do you want to trigger a scheduled script from a script action? The way I see it, whatever is in the Scheduled Script that the Script Action should trigger, belongs into a Script Include and that is what the Script Action should trigger instead.

Also, to better understand what's going on, could you show how is scheduleGr created and queried - in the Scheduled Script?

couple of reasons,

  • the second scheduled script is an OnDemand one and I am unable to calculate the precise time at which that needs to be run.
  • second script is dependent on the completion of a first scheduled job which processes 1M+ records.
  • I am doing some estimate on the processing time of the records based on the count + buffer time and creates a scheduled event ( which invokes the script action & thereby triggering sched job )

Hope that makes sense.

 

SchedGr is created based on the first schedule and a function inside it. ( pass the count and the next script name)

 var gdt = new GlideDateTime();
 var totalTimeMs = count * 2000 + 120000; // test values
        gdt.add(totalTimeMs);
        var schedGr = new GlideRecord('sysauto_script');
        schedGr.addQuery('name', autoScriptName);
        schedGr.query();
		
        if (schedGr.next()){
			
			
			gs.eventQueueScheduled('x_abc_scope.trigger_nxt_sch', schedGr, "trigger_next_job", schedGr.getUniqueValue(), gdt);
			return 'success';
		}
		else
			return 'failed';