SCHEDULED JOB TO RUN EVERY SECOND ?

sukran
Mega Sage

Is this possible to run schedule job every second ? To check records and trigger a email event queue

 

I tried that but it's missed to do action for some record..

Or how to trim the date //Time field for second value so that we can try to run schedule job every minute...Is this right way ? Plz guide

12 REPLIES 12

What are you trying to notify them of?  Is it just a reminder that they only have 30 minutes left to complete a change?  It seems unnecessary to try and alert people to mind them of their job especially when OOB the system send out a calendar invite to the person assigned to perform the change.

DrewW
Mega Sage
Mega Sage

Just use an on update business rule to trigger what you need.  So any time the planned date changes use

gs.eventQueueScheduled("EVENT", task, parm1, parm2, DateTime of trigger);

Then use a script action to check to see if you are within 28 to 32 minutes of the planned date and if you are trigger the notification.  If not do nothing.

If you do not want to try and check the date range then before you trigger the event on a schedule check to see if there is already one in the sysevent table that is not processed and if so update the process on field to the new planned date.

 

Hi Drew

 

Thats help me and it trigger a alert mail , Thank you

I found two issues while triggering mails 

 

1- if we set past day as planned start day and end date , its triggers a mail immediately ( ex : i mentioned yesterday date/time ) but its should n't trigger if its not same date as today

 

2- also 12am time trigger ( i set 3/7/2020 12am as planned date ) its should trigger a mail 30 min before on 3/6/2020 11.30pm ) functionally this is correct

but the custom field take and set as ( 3/7/2020 11.30 am ) - it should be happen , any idea on this ?

For 1 this sounds like you need to update the code so that it does not create the event when it will trigger before today.

For 2 its either a time zone issue or how you are doing your math, I suspect the later.  Midnight is 00:00 so depending on how you did your math you may not be going back a day.  You should just be able to do something like the below and it will work regardless.

var dt = current.planned_start.getGlideObject();
dt.addSeconds(60 * 30 * -1); //60 seconds times 30 minute times -1 to get it to subtract.

Hi,

Just wondering that how business rule will be triggered? If the scenario is like my end date time is tomorrow 1:30pm so mail is supposed to get triggered around 1:00pm but what If the record is not updated at that particular time interval? So there will be no update and no update means no Business rule and if there is no business rule then neither event will be triggered nor the notification.

I believe schedule job with 30 minutes frequency will be a good one which will check for all the records with the end time between next 30 to 60 minutes. Please find the below sample code which could be used for the same:

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('end_dateRELATIVELE@minute@ahead@60^end_dateRELATIVEGE@minute@ahead@30^active=true');// it will check for the active records with the end date after 30 minutes and before 60 minutes.
gr.query();
while(gr.next()){
	gs.eventqueue ( notify.enddate , gr, param1, param2 );
}

Kindly mark my answer as Correct and Helpful based on the Impact.

Regards,

Alok