gs.eventQueueScheduled not working as expected even if supplied with correct arguments

Milan13
Giga Expert

Hello,

I need to trigger an event using business rule on problem_task table once due_date changes, need to subtract 12hrs from due_date and at that time notification needs to be triggered using an event.

The problem is that the event is triggered and notification is sent , but immediately, not 12hrs prior to the due_date time.

Please see below code, when checking log the time is always due_date - 12hrs, the date arithmetics just works but it seems the gs.eventQueueScheduled method does not recognize it for some rreason, I also checked the date format and it's just fine.

Can anyone please help?

Thanks a lot, Milan

(function executeRule(current, previous /*null when async*/) {

var gdt = new GlideDateTime();
gdt.setValue(current.due_date.getDisplayValue());
gdt.addSeconds(-43200);
var due_date_reminder = gdt.getValue();
gs.log('MILAN STORY 75: ' + due_date_reminder);

gs.eventQueueScheduled('problem.task.duedate', current, 'parm1', 'parm2' , due_date_reminder);


})(current, previous);

 

1 ACCEPTED SOLUTION

Milan13
Giga Expert

So, finally , this works...

 

(function executeRule(current, previous /*null when async*/) {

var dueDate=current.due_date;
var gdt = new GlideDateTime(dueDate);
gdt.subtract(43200000);
gs.eventQueueScheduled('problem.task.duedate', current, 'parm1', 'parm2', gdt);

})(current, previous);

View solution in original post

15 REPLIES 15

AbhishekGardade
Giga Sage

Hello Milan,

Please try below code 

var dueDate=current.getValue('u_off_hold_date'); //u_off_hold_date
//gs.log("AVG dueDate:"+dueDate);
var gdt = new GlideDateTime(dueDate);
//gs.log("AVG gDT:"+gdt.getValue());
gdt.subtract(43200000); // replace Miliseconds which you want to substract
var taskActivationTime=gdt.getValue();
gs.eventQueueScheduled('incident.ConferenceTask', current, gs.getUserID(), gs.getUserName(), gdt); // replace parm1 and parm2 with your values that you want to pass.

Please mark answer correct if you find it as helpful.
Thanks,
Abhishek Gardade
Thank you,
Abhishek Gardade

Hi Abhishek,

thanks for your advice, it still does not work however I have found out one thing:

Even if I put just the datetime value itself (from problem_task due_date field) as a last argument - code snippet below - the event gets fired immediately like it was not not taking the datetime parameter into consideration at all...

gs.eventQueueScheduled('problem.task.duedate', current, 'parm1', 'parm2' , current.due_date.getDisplayValue());

 

I used this before in case of datetime field on an incident form and it worked.

Any idea why this is so?

Appreciate your help,

Milan

Can you try with this line

gr.addQuery("due_date", "<", gs.hoursAgo(12));//less than 12 hours

or

gr.addQuery("due_date", "=", gs.hoursAgo(12));//less than 12 hours

Regards
Harish

Can try like this


var gr = new GlideRecord('problem_task');
gr.addQuery("due_date", "<", gs.hoursAgo(-12));//less than 12 hours
gr.query();

if(gr.next())
{
gs.print("inside if");

}

Link: https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GS-hoursAgo_N

Regards
Harish

Can try like this


var gr = new GlideRecord('problem_task');
gr.addQuery("due_date", "<", gs.hoursAgo(-12));//less than 12 hurs
gr.query();

if(gr.next())
{
gs.print("inside if");

}

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GS-hoursAgo_N

Regards
Harish