How to send notification based on time interval

Nag9
Tera Expert

In my req

I want to send notifications to the owner of the story, if state changes to UAT and testing will not happen upto 2 days.

So need to set reminder for the story owner after 48 hours , still story testing pending 

I created event and business rule but its not wrking

 

Can anyone help me out on this

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi Nag,

Instead of BR, try scheduled job. Because with BR, once the event is scheduled, it will trigger event irrespective of update happened later or not. Since you want to send notif only if there is no update in 2 days after state changes to UAT, it is better to try with scheduled script.

var gr = new GlideRecord("rm_story");
gr.addEncodedQuery("sys_updated_on<javascript:gs.beginningOfYesterday()^state=1"); //place value of UAT here
gr.query();
while(gr.next())
{
gs.eventQueue('your_event_name',gr,gs.getUserName(),gs.getUserID()); 
}

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

View solution in original post

18 REPLIES 18

For 2 days, we cannot build encoded query directly. you can try something like this.

var gdt = new GlideDateTime();
gdt.addDays(-2);
var gr = new GlideRecord("rm_story");
gr.addQuery("state=1"); //place value of UAT here
gr.addQuery("sys_updated_on","<",gdt);
gr.query();
while(gr.next())
{
    gs.eventQueue('your_event_name',gr,gs.getUserName(),gs.getUserID()); 
}


Mark the comment as helpful if it helps.

ravi32
Tera Contributor

On hold reason = waiting information and   Follow up = true mails are receiving every time interval but the problem is

for testing purpose , if I run scheduled job for 1 hour , when one INC0010077 is updated at 9:00 AM and another INC0010078 updated at 09:30 AM the  scheduled job runs with both tickets sending notification at a 10:00 Am time, but second INC0010078 send notification at 10:30.not sending at correct time.

 

var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^state=3^hold_reason=6^u_automatic_follow_up=true");
gr.query();
while(gr.next())
{
 
gs.eventQueue('Automatic follow up', gr, gr.getValue('user'));


}find_real_file.png

ravi32
Tera Contributor

On hold reason = waiting information and   Follow up = true mails are receiving every time interval but the problem is

for testing purpose , if I run scheduled job for 1 hour , when one INC0010077 is updated at 9:00 AM and another INC0010078 updated at 09:30 AM the  scheduled job runs with both tickets sending notification at a 10:00 Am time, but second INC0010078 send notification at 10:30.not sending.

For last working 3 days, last working 5days and 7 days, how could we? write the condition?