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

How to create approval notification in workflow with the different dates

Sireesha7
Tera Contributor

Hi All,

 

We have a custom table, once user create a record it need to send an email notification for below conditions:

1)when record got created it will go for an approvals

2)when status is waiting for validation and record is going to expire in 49 days (7 weeks) it will sent reminder notification to approve the record 

3)when status is waiting for validation and record is going to expire in 42 days (6 weeks) it will sent reminder notification to approve the record

4)when status is waiting for validation and record is going to expire in  35 days (5weeks) it will sent reminder notification to approve the record

5)when status is waiting for validation and record is going to expire in 28 days (4weeks) it will sent reminder notification to approve the record

6)when status is waiting for validation and record is going to expire in 14 days (2 weeks) it will sent reminder notification to approve the record

 

Could you please help me  and let me know how to achieve this?

 

Thanks in advance.

 

Regards,

Sireesha.

1 ACCEPTED SOLUTION

Tony Chatfield1
Kilo Patron

Hi, I would consider a scheduled job set to run once a day outside of core business hours

Product Documentation | ServiceNow

In the job add a script to query for all records that meet the 'waiting for validation' criteria from your table.

Then in a while loop test each record to see if it meets your data range requirements.


GlideDuration subtract() and getDayPart() may be a simple way to return a numerical value that you can then test against your date ranges.
GlideDuration | ServiceNow Developers

You can then test the date part and if it meets your requirement trigger a notification via a sysevent.

GlideSystem | ServiceNow Developers

If triggering the same sysevent for each notification, you can include multiple date checks in your 'if' condition,
or use separate if statements (or a switch\case) for triggering separate sysevents for separate notifications.

Untested so may have syntax\functional errors, but something like.

var recordCheck = new GlideRecord('some_table');
recordCheck.addQuery('referenceField', 'referenceValue'); //or use an encoded query
recordCheck.query();

while(recordCheck.next()) {
//your records reference due date\expires field
var referenceDate =  = new GlideDateTime(recordCheck.someDateTimeField);

//get the date/time for right now
var nowTime = new GlideDateTime();
var dur = new GlideDuration();
//now compare the 2 dates
dur = GlideDateTime.subtract(nowTime, referenceDate);
//get the resulting days difference as a number
var daysLeft = dur.getDayPart();
gs.info('Days ' + days);
//test the number against your date range
if(daysLeft == 14 || daysLeft == 28 ) {
        //trigger a sysevent
	gs.eventQueue('your.registered.event', recordCheck, recordCheck.someUserField, 'otherdetailsIfRequired');
	}
}

 

View solution in original post

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, I would consider a scheduled job set to run once a day outside of core business hours

Product Documentation | ServiceNow

In the job add a script to query for all records that meet the 'waiting for validation' criteria from your table.

Then in a while loop test each record to see if it meets your data range requirements.


GlideDuration subtract() and getDayPart() may be a simple way to return a numerical value that you can then test against your date ranges.
GlideDuration | ServiceNow Developers

You can then test the date part and if it meets your requirement trigger a notification via a sysevent.

GlideSystem | ServiceNow Developers

If triggering the same sysevent for each notification, you can include multiple date checks in your 'if' condition,
or use separate if statements (or a switch\case) for triggering separate sysevents for separate notifications.

Untested so may have syntax\functional errors, but something like.

var recordCheck = new GlideRecord('some_table');
recordCheck.addQuery('referenceField', 'referenceValue'); //or use an encoded query
recordCheck.query();

while(recordCheck.next()) {
//your records reference due date\expires field
var referenceDate =  = new GlideDateTime(recordCheck.someDateTimeField);

//get the date/time for right now
var nowTime = new GlideDateTime();
var dur = new GlideDuration();
//now compare the 2 dates
dur = GlideDateTime.subtract(nowTime, referenceDate);
//get the resulting days difference as a number
var daysLeft = dur.getDayPart();
gs.info('Days ' + days);
//test the number against your date range
if(daysLeft == 14 || daysLeft == 28 ) {
        //trigger a sysevent
	gs.eventQueue('your.registered.event', recordCheck, recordCheck.someUserField, 'otherdetailsIfRequired');
	}
}