Check if P1 INC is being updated evry 1hr, if not Send an email notify to the manager of Assigned to

saipragna
Tera Contributor

When the P1 INC work notes/ comments are not updated every 1 hour, email should be sent to the manager of Assigned to user. Can someone help me to achieve this.

 

Thank you

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @saipragna ,

You can achieve this using a Flow. Create a flow which will be attached to the P1 incidents and wait for an hour and check if there is an update in work notes/comments or not in last 1 hour and trigger an email to the manager if there is no update. You can try this approach,


1. Create a Flow Action which returns the difference between input time and current time, like the one below.

AnveshKumarM_0-1678167349823.png

AnveshKumarM_1-1678167391018.png

AnveshKumarM_2-1678167415816.png

AnveshKumarM_3-1678167457075.png

Use the below script in script step of the action.

(function execute(inputs, outputs) {
  var current_time = new GlideDateTime();
  var diffSeconds = gs.dateDiff(inputs.last_updated, current_time, true);
  diffMins = diffSeconds/60;
  diffMins = Math.round(diffMins);
  outputs.diff = diffMins;

})(inputs, outputs);

2. Create a flow which will check for the last update on comments/worknotes every 10 minutes and triggers an email to assigned to manager if there is no update in last 1 hour.

AnveshKumarM_4-1678167577542.png

AnveshKumarM_5-1678167612108.png

2-A. Look up for last comments/worknotes in sys_journal_field table.

AnveshKumarM_7-1678167732201.png

2-B: Check if a valid record is returned.

AnveshKumarM_8-1678167791268.png

 

2-C: If a valid record is found, get the time difference between now and last comment updated time.

AnveshKumarM_9-1678167839745.png

2-D: Check if the time difference is more than 1 hour

AnveshKumarM_10-1678167878796.png

 

2-E: If the update is more than 1 hour, send an email to assigned to user manager.

AnveshKumarM_11-1678167949869.png

AnveshKumarM_12-1678167965777.png

2-F: Wait for 10 minutes before next iteration.

AnveshKumarM_13-1678168013900.png

2-G: If the incident is resolved, get out of the loop and end the flow.

AnveshKumarM_14-1678168053831.png

 

Please let me know, if you face any difficulties using this.

 

Thanks,

Anvesh

 

 

 

 

 

 

 

 

 

 

 

 

Thanks,
Anvesh

View solution in original post

9 REPLIES 9

@AnveshKumar M  I just want to know why you have used explicit duration. Can you please explain?

@saipragna , I just wanted to wait for some duration (I set it to 10 Mins, you can change according to your needs) before I can check the updates again, that way I can reduce the number of iterations and reduce resource utilization. "Explicit Duration" seemed to fit in that context.

 

Please feel free to share your thoughts if we can improve this context.

 

Thanks,

Anvesh

Thanks,
Anvesh

However, I don't think it is taking the exact minutes. In my instance, this loop is running continuously for every minute. In the explicit duration I have given 1 hour. Can you please check once

 

From flow execution logs in my instance, I can see the explicit timer is working as expected, in the screenshot below, you can see the timer got triggered 2023-03-12 21:44:02 and will continue the next iteration after 2023-03-12 21:54:02. Try checking the execution logs. 

 

Note: With the current design of flow, Each P1 incident will have it's own instance of flow running for it. If we have 5 P1 incidents, we will have 5 instance of flow running.

 

AnveshKumarM_0-1678682839062.png

 

AnveshKumarM_1-1678682934100.png

 

 

Thanks,
Anvesh

TrevorK
Kilo Sage

I can think of two potential ways to handle this:

a) Scheduled job: You would have a scheduled job that runs at certain intervals and scans your instance for the records which meet your criteria (P1, Active, No updates to work notes in past hour). If criteria is met, you fire off the email. While it sounds great, the downside is that it will not be precise. if your scheduled job runs every 5 minutes, it will find records between 60 and 65 minutes old. Perhaps that is acceptable, but just some caution.

Yes you could run the scheduled job every minute but because of the solution below, I'm not sure I would explore that.

 

b) Script action: I find this method is not used often, but I think it's perfect for your use case. It does require a bit more process mapping, but I'll give the rough idea. When an Incident is moved to being a P1 you create an event (gs.eventQueueScheduled) for 1 hour in the future. You then create a Script Action to watch for this event, and within your code do all the evaluation for whether you want to trigger the notification (Incident still P1, Incident is Active, no work notes or comments in past hour) at that 1 hour mark. If you do want to send the email, then trigger the notification. If you do not, then look at your P1 Incident and determine the last work note / comment, add an hour to it, and scheduled the event (gs.eventQueueScheduled) for 1 hour after that. 

We look for the last work note / comment because it may have happened at the 33 minute mark, so we want to re-evaluate one hour from that last update time, not one hour from when we last ran this script. I hope this makes sense and does not confuse it.

 

Option B is what I would consider the best option of the two. It requires just a bit more thought, but it will work very well at treating each P1 Incident independently. Option A would have you running a scheduled job all the time to keep looking for these P1 Incidents and that is a waste of resources. Your instance can handle it, but I think it's just a bit wasteful. 

 

Option B on the other hand executes only when needed. It is much more precise in terms of timing and nothing runs if you have no P1 Incidents. More efficient and I would say better practice.

 

Here is where you find Script Actions:

TrevorK_0-1678172070258.png

 

Documentation on Script actions:

https://docs.servicenow.com/en-US/bundle/utah-platform-administration/page/administer/platform-event...

 

Documentation on gs.eventQueueScheduled:

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideSystemAPI#GS-even...

 

Hope that helps!