Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Approval on Catalog Item

Mahesho11
Tera Contributor

Hi All,

I have the requirement Please help me in detail to achieve this.

Process Summary:

1. Day 0: Initial approval request is sent.

2. Day 2: 1st reminder is sent after 2 days of the initial request.

3. Day 5: 2nd reminder is sent after 3 days from the 1st reminder.

4. Day 7: 3rd reminder is sent after 2 days from the 2nd reminder.

5. If no action is taken after the 3rd reminder:

Request is escalated to the next level manager on Day 7.

Next level manager has 5 days (until Day 12) to approve the request via email.

If no action is taken by the next level manager by Day 12, the request expires.

 

Summary:

Day 0-7: Reminders are sent sequentially if no action is taken.

Day 7: Escalation occurs.

Day 7-12: Next level manager has 5 days to approve after escalation.

Day 12: Request expires if no action is taken by next level manager.

2 REPLIES 2

Addy22
Tera Guru

Hi @Mahesho11 ,

 

You can achieve it by using ScheduleOnce()

 

The steps would be :

1) Calling a script inlcude when form submits(Use BR / onSubmit CS)

2) Refer below script for script include. Modify it according to your use

3) Add more functions like notifyUserAfterTwoDay for 7 and 10 days approval

4) So all the notiifcations will be scheduled and when they will run , if the record is approved abort sending notification(as mentioned in below script)

5) You can find scheduled notification here - sys_trigger table

 


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

scheduleNotifications: function(record) {

        

 

            //Setting up future date to send notification after 3 days from submission of form

            var firstNotificationDate = new GlideDateTime();

            firstNotificationDate.addDaysUTC(2);

 

 

            //scheduling first notification after 2 days from submission of form

 

            var scheduledExecution = new ScheduleOnce();

            scheduledExecution.script = 'new testScriptInclude().notifyUserAfterTwoDay ("' + record.getUniqueValue() + '","' + record.requestedFor + '")';

            scheduledExecution.setTime(firstNotificationDate);

            scheduledExecution.setLabel(’SecondDayNotification’);

            scheduledExecution.setDocument(record);

            scheduledExecution.schedule()

        }

 

    },

 

    notifyUserAfterTwoDay : function(record,userSysId ) {

        Use glide record on approval table, if

        if (it is not approved for the current record) {

            //notify user

            gs.eventQueue(‘event name’, record, userSysId);

        }

 

    }

 

 

 

 

Similarly, you need write more functions according to your requirement days. It will work fine.

Community Alums
Not applicable

Hi @Mahesho11 ,

Please follow below steps 

1. Create events for each day of notification like

All< System Policy < Event< Registry 

a. Create Event for 1st day of notification 

Table - sc_req_item

and save, repeat for each day of notification 

 

2. Create business rule to trigger that event 

Before update and insert business rule and table - sc_req_item

and add below scirpt 

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

	// Add your code here
	var currentDate = new GlideDateTime();
	var gr = new GlideRecord("sysapproval_approver");
	gr.addEncodedQuery("sysapproval.numberSTARTSWITH", current.sys_id);
	gr.query();
	if(gr.next()){
		var addOneDay = new GlideDateTime();
		addOneDay.addDays(1);
		if(currentDate == addOneDay){
			gs.eventQueue('event.for.first.reminder', current,  current.requested_for, current.requested_for.manager);
		}
		var addTwoDay = new GlideDateTime();
		addTwoDay.addDays(2);
		if(currentDate == addTwoDay){
			gs.eventQueue('event.for.second.reminder', current,  current.requested_for, current.requested_for.manager);
		}

	}

})(current, previous);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak