How to implement 3 strike rule( send emails automatically)?

gkbhandare003
Kilo Guru

Hi All,
I am trying to design a solution where, the ticket is pending awaiting user response - if there no update from user within 24 hours, the email will be send and same on 48 and 72 hours.
if the user updates tickets, flow breaks and ticket status changes.

Considerations:
1.Ticket Status: Pending, awaiting User response.

2.Flow/rule executes: condition 1 is true and there is no update from user in ticket for 24, 48,73 hrs

3. Rule should: send email to user with defined template.

4.Tried to create scheduled job and event, notification - no luck with that. 

I have tried to create a Scheduled job for this, but no luck.
Script:

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^state=3^sys_updated_onMORETHANsys_updated_on@day@after@1^sys_updated_by!=caller_id');

gr.query();

while (gr.next()) {

gs.eventQueue("chase.process", gr);
}

I have created event and notification for the same, but it is not working as expected.

Do we have any OOB solution for this or any advise on how can we achieve this?
Please advise..

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Dubz
Mega Sage

This sounds like a perfect use case for Flow tbh, not sure why you would use s scheduled job for this? Something like the below will send an email every 24 hours until the updated by is set to the caller. You'd need to refine it of course but it'll probably be more effective than a scheduled job and easier to configure and administer.

find_real_file.png

View solution in original post

12 REPLIES 12

Harsh Vardhan
Giga Patron

are you directly using the caller field on your notification ?  if not then you have to pass it on your event param 1 parameter. 

 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^state=3^sys_updated_onMORETHANsys_updated_on@day@after@1^sys_updated_by!=caller_id');

gr.query();

while (gr.next()) {

gs.eventQueue("chase.process", gr, gr.caller_id,'');
}

 

Now, go to your notification and set the true on "Event parm 1 contains recipient" field. 

 

once you will execute your scheduled job , check the event logs to confirm if you event has been executed or not. 

 

AbhishekGardade
Giga Sage

Hello Ganesh,

1. Create 3 Events on incident table in event registry.

    Event Names:

  • incident.firstReminder
  • incident.secondReminder
  • incident.thirdReminder   

2. Create after update Business rule with conditions STATE CHANGES to pending awaiting user response

Add below code:

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

var gdt = new GlideDateTime();

gdt.addDaysLocalTime(1);
var firstReminder = gdt ;
gs.log("firstReminder: "+firstReminder);
gs.eventQueueScheduled ("incident.firstReminder" , current , gs.getUserID(), gs.getUserName(), firstReminder);

gdt.addDaysLocalTime(1);
var secondReminder = gdt ;
gs.log("secondReminder: "+secondReminder);
gs.eventQueueScheduled ("incident.secondReminder" , current , gs.getUserID(), gs.getUserName(), secondReminder);

gdt.addDaysLocalTime(1);
var thirdReminder = gdt ;
gs.log("thirdReminder: "+thirdReminder);
gs.eventQueueScheduled ("incident.thirdReminder" , current , gs.getUserName(), thirdReminder);

})(current, previous);

3. Create 3 Notifications for sending these three notifications with run condition is fired by event and STATE CHANGES to pending awaiting user response. Add your content whatever you want. Also you can add who will receive to send notifications to users.

You can see in Event Log when your notifications will trigger:

find_real_file.png

 

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade
Hexaware Technologies Inc.

Thank you,
Abhishek Gardade

dvp
Mega Sage
Mega Sage

The issue is with your Query. You have updated by is not caller_id  which is not a valid filter.

The FIlter should be something like below.

find_real_file.png

the above filter provides you the records that are not updated before 1 day. so as per your requirement you have to restrict it to between 24 to 72 hours

 

checking if the updated by is not caller should be done in while loop

 

script

while (gr.next()) {

if(gr.sys_updated_by != gr.caller_id.user_name)
    gs.eventQueue("chase.process", gr);
}

Dubz
Mega Sage

This sounds like a perfect use case for Flow tbh, not sure why you would use s scheduled job for this? Something like the below will send an email every 24 hours until the updated by is set to the caller. You'd need to refine it of course but it'll probably be more effective than a scheduled job and easier to configure and administer.

find_real_file.png