Exclude week ends for sending remainder notification for approver of request .

Bhanupriya
Giga Contributor

Hi All,

    I have following requirement to send  the remainder notification.

Scenario: Service Requests which have Approval workflow defined needs to be approved within 2 weeks (14 Calendar days) of creation. If the request is not approved within 2 Weeks the request will get auto rejected and the requested for has to be notified accordingly. The  week ends should be excluded when we send the Remainder notification on 0th day ,5th Day.10th Day and 14th Day .Please do let me know how to achieve  this in workflow as soon as possible.               

Notifications needs to be triggered as mentioned in the table below.

 

Day

Trigger

Users to be notified

Request Stage

Task State

Day 0

Notification 1

Approver

Waiting for approval

Requested

Day 5

Notification 2

Approver

Waiting for approval

Requested

Day 10

Notification 3

Approver

Waiting for approval

Requested

Day14

Notification 4

Approver & Requested for

Closed Incomplete

Cancelled

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Bhanupriya 

you can run daily scheduled job and check the difference between created and now time and based on that send email

I have shared solution something similar earlier; enhance as per your requirement

sendEmail();

function sendEmail(){
	try{
		var gr = new GlideRecord('sysapproval_approver');
		// add extra query if required
		gr.addQuery('state=requested');
		gr.query();
		while(gr.next()){
			var gdt = new GlideDateTime(gr.sys_created_on);
			var nowTime = new GlideDateTime();

			var duration = GlideDateTime.subtract(gdt, nowTime);
			var days = duration.getDayPart();
			if(days == 0 || days == 5 || days == 10 || days == 14){
				gs.eventQueue("event_name", gr, 'your recipients');
			}
		}
	}
	catch(ex){
		gs.info('Exception'+ex);
	}
}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

You can use something of the below code to implement this:-

 

var result = true;
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeekLocalTime(); //The day of week value from 1 to 7. Monday equals 1, Sunday equals 7.
if (day == 6 || day == 7)
result = false;
result;

Ankur Bawiskar
Tera Patron
Tera Patron

@Bhanupriya 

you can run daily scheduled job and check the difference between created and now time and based on that send email

I have shared solution something similar earlier; enhance as per your requirement

sendEmail();

function sendEmail(){
	try{
		var gr = new GlideRecord('sysapproval_approver');
		// add extra query if required
		gr.addQuery('state=requested');
		gr.query();
		while(gr.next()){
			var gdt = new GlideDateTime(gr.sys_created_on);
			var nowTime = new GlideDateTime();

			var duration = GlideDateTime.subtract(gdt, nowTime);
			var days = duration.getDayPart();
			if(days == 0 || days == 5 || days == 10 || days == 14){
				gs.eventQueue("event_name", gr, 'your recipients');
			}
		}
	}
	catch(ex){
		gs.info('Exception'+ex);
	}
}

Regards
Ankur

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

@Bhanupriya 

Did you get a chance to check on my above response?

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