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.

Fill the details by the Date in the email body

anitha arugonda
Tera Contributor

Heyy,

I have a requirement that... ticket get closed on 9th day from opening, Remainder notification will trigger till every 2 business days(schedule created) till 8th day. Now I request assistance on.. the body of notification contains a statement that..”fill the details by 8th day". Example: ticket created on 13th may then body should contain ” fill the details by 24th May" here the day calculation should exclude holidays and weekends.

 

Thanks in advance.

 

#notifications#emailscripts#date

 

1 REPLY 1

Tony Chatfield1
Kilo Patron

Hi, unfortunately date\time values in email notifications are not always simple to configure, as a specific notification may be triggered to multiple recipients across multiple time-zones. If your scenario is a 1 notification to 1 recipient, then you should be able to configure a notification email script to populate the required date.

Taking a look at GlideSchedule
GlideSchedule | ServiceNow Developers

You should be able to instantiate using a predefined schedule, and users time-zone (if necessary), then use the add() method to calculate your required date value.

 

Here a rough example based on the example from the API documentation,
I have allowed for various TZ's but you could potentially hard code.

// need to set the default TZ if the TZ sys property is empty
var myTZ = (gs.getProperty('glide.sys.default.tz')) ? gs.getProperty('glide.sys.default.tz') : 'America/Los_Angeles';

// dot.walk the task/reference record to the relevent user field eg current.someField
var userID = 'ad72954997c20690de083fd0f053afd7';
var myUser = new GlideRecord('sys_user');
myUser.get(userID);
myTZ = (myUser.time_zone != '') ? myUser.time_zone : myTZ;

//dot.walk to task field IE current.somedateTimeField
var startDate = '2024-05-14 10:00:00'

var startDate = new GlideDateTime(startDate);
//This example is for 9 hour days, you would need to adjust for length of your business day or set to 24.
var days = 7;
var dur = new GlideDuration(60 * 60 * 9 * 1000 * days);
//set your schedule and TZ
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828', myTZ);
var end = schedule.add(startDate, dur);
gs.info('result ' + end);