- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2019 03:35 AM
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);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2019 03:24 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 01:38 AM
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.
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 09:41 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 09:54 PM
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
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 10:01 PM
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
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2019 10:02 PM
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
Harish