Firing Events from scheduled Jobs

sigmachiuta
Kilo Guru

I am trying to figure out the 'best' method to notify/ re notify if changed users of an activity.   I have another post where i was trying to do this with a workflow but I am thinking a scheduled job might be the safest bet.

I am trying to fire an event from a scheduled job when the follow up date is within 1 minute.   I am running the job every 2 minutes and I am checking if the notification field is within 1 minutes or less and the same field and its not greater than 2 minutes ago is there a better method of checking this notification field to trigger this scheduled job that fires off this email?

var gr = new GlideRecord('incident');

gr.addQuery('active', true);

gr.addQuery('state',4)

gr.query();

gr.next();

while(gr.next()){

if ('u_notification', '=<', gs.minutesAgo(1) && 'u_notification', '!=>', gs.minutesAgo(2)); {

//set state

gr.addQuery('state',1)

// Fire event to send email

gs.eventQueue("incident.notification", current)

};

}

6 REPLIES 6

I am not sure where i am going wrong my event is not firing and my state is not changing.     Maybe I have an error in my syntax?


I have checked and the job is running but its not processing anything.



var gr = new GlideRecord('incident');


gr.addQuery('active', true);


gr.addQuery('state',4);


gr.query();




while(gr.next()){




//set state


if (gr.u_notification >= gs.minutesAgo(1) && gr.u_notification <= gs.minutesAgo(2)) {



//set state


gr.state = 1;


gr.update();


// Fire event to send email


gs.eventQueue('incident.notification', gr, null, null);




}


}


Hi:



a) make sure your if (line 11) is right. I'm almost sure the problem is in that line


b) make sure that the format of your u_notification field is comparable with the one retrieved by gs.minutesAgo()


c) since you're using a relative comparison with a very short time period, it's almost required that your schedule job runs every minute based on how you have set it up. If possible, consider using different timeframes.



Thanks,


Berny