The CreatorCon Call for Content is officially open! Get started here.

Scheduled Job for change request

MarripudiL
Tera Contributor

Hi All,

 

 we need a scheduled job script to send a reminder mail to users before one day of start date in change request.

if the scheduled start is on Monday then the email on Friday(working day) , for remaining it should trigger the one day before.

 

Thanks in advance.

 

4 REPLIES 4

Shivalika
Mega Sage
Mega Sage

Hello @MarripudiL 

 

You can add the condition as shownkn below screenshots in your email notification and it will trigger. 

 

Planned start date - relative - after - 1 Day Ago 

 

1000020790.jpg

 

This will trigger the email as soon as 1 day ago timeline is finished. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw

NeEISQCY

Ankur Bawiskar
Tera Patron
Tera Patron

@MarripudiL 

you cannot configure notification for this

For this you need to do this

1) configure daily scheduled job

2) iterate CHG

3) get the start date and subtract 1 day from that using Schedule or simply skip weekends for your calculation

4) the date which you get from Step 3 compare it with Today's date

5) if same then trigger event using eventQueue() and configure notification to trigger on that event

sharing link for step 3

Calculate Date By Adding or Subtracting Time With A Schedule 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@MarripudiL 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Neeraj31
Mega Sage

Hi @MarripudiL ,

 

You can use DurationCalculator Script Include to check the difference between current Date and Start Date using Schedule.
Create one 24X7 excluding Weekend schedule and use it like below code.

var dc = new DurationCalculator();
dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); // Schedule 24X7 excluding Weekends

var nowDate= new Date();

var gr = new GlideRecord('change_request');
gr.addQuery('active', true);
gr.query();

while(gr.next()) {
	var diff = dc.calcScheduleDuration(nowDate , gr.start_date) / (60*60*24);
	if(diff <= 1 && diff > 0) { 
		gs.log(gr.number); // Create event for Notifications
	}
}

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway