How to Implement Daily Notifications for Past Planned Start Dates in Change Requests

LokeshwarRV
Tera Contributor

Hi everyone,

I'm working on a functionality in ServiceNow to send daily notifications to the requestor and assigned person when a Change Request's planned start date is in the past, and the state is either Scheduled or Implement. Below are the steps I've followed using scripting and notifications:
i have create one shedule job with script 

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('stateIN-3,4^planned_start_date<javascript&colon;gs.beginningOfToday()'); // 3 = Scheduled, 4 = Implement
gr.query();

while (gr.next()) {
var requestor = gr.requested_by;
var assignedTo = gr.assigned_to;

var notification = new GlideEmailOutbound();

if (requestor) {
gs.eventQueue('change.planned_start_passed', gr, requestor.sys_id, '');
}
if (assignedTo) {
gs.eventQueue('change.planned_start_passed', gr, assignedTo.sys_id, '');
}
}
and i have created event registry and then in notification can you help me what i have to do

 

3 REPLIES 3

Brian Lancaster
Tera Sage

You should not need this line of code.

var notification = new GlideEmailOutbound();

In your gs.evenQueue just user requestor and assignedTo instead of requestor.sys_id and assignedTo.sys_id. When you do var requestor = gr.requested_by; that is the sys_id.

var gr = new GlideRecord('change_request');
gr.addEncodedQuery('stateIN-3,4^planned_start_date<javascript&colon;gs.beginningOfToday()'); // 3 = Scheduled, 4 = Implement
gr.query();

while (gr.next()) {
var requestor = gr.requested_by;
var assignedTo = gr.assigned_to;

if (requestor) {
gs.eventQueue('change.planned_start_passed', gr, requestor, '');
}
if (assignedTo) {
gs.eventQueue('change.planned_start_passed', gr, assignedTo, '');
}
}

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @LokeshwarRV 

You can easily do this via Flow Designer, where no coding is required. Just add a “Look Up Records” step to get the records, then use the notification action to send the emails. It’s a simple and easy way to do it.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Rakesh18081
Tera Expert

Do it via Flow designer, the trigger would every time start date is updated, then call an action to check if the date is in past. If it's in past trigger the event to send out notification.

No need of loop the flow would trigger for each unique change.

 

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." 

Regards
Rakesh Agarwal