SUBHAM_SHAW_SN
Tera Guru
Tera Guru

Scenario : Compare a given date with the current date in order to send a reminder notification after N number of days have been passed based on the updated timestamp of a record

 

Traditional approach

The logic that generally comes to our mind is comparing the time stamps using the function dateDiff.
The earlier approach was to create scheduled job with a script to compare dates and perform the operation.

Disadvantages : dateDiff() is not available to be used within scoped applications. In addition,  it also requires scripting where we need to play with two date fields. Trust me it's not fun. 😛 

 

Low code approach

We can leverage the flow engine of ServiceNow. By now, you might be thinking that I am going to talk about building a custom action and playing within that. Be assured , this is not the case.

 

We will be using transform functions available within a flow. Along side ,we will be using a schedule date trigger to run a flow daily  . Here you go :

 

Step 1 : If you look at the below screenshot , you could see that I have used "Add time" function and added the duration . E.g. I wanted to fire a notification after 164 days from now or I could say on the 165th day.

find_real_file.png

 

Step 2 : We need to convert the date to string(for better comparison) using a second transform function called "Date to String"  and set an output format

find_real_file.png

 

Step 3 : Compare the date(i.e . string version of updated time+164 days)with the trigger date(will be the current date as the flow runs daily). Before making the comparison, please make sure that you are also deriving the string version of the trigger/current date. Once done, use an if logic to compare the dates and you are all sorted.

find_real_file.png

 

 

Happy learning !

 

Cheers,

Subham Kumar Shaw

Senior ServiceNow Consultant

 

 

 

Comments
Uncle Rob
Kilo Patron

Had no idea about the Add Time transform, and low key I'd thought of building a custom action for it.

Thanks for the time save.

SUBHAM_SHAW_SN
Tera Guru
Tera Guru
Glad that you liked it 🤓
Rohit Sarkar1
Mega Guru
Great content reduces risk of method depreciation and forward compatibility!
SUBHAM_SHAW_SN
Tera Guru
Tera Guru

Absolutely

MrMuhammad
Giga Sage

Nice and Short. Great Content! 

SUBHAM_SHAW_SN
Tera Guru
Tera Guru

Thanks mate

Version history
Last update:
‎07-01-2022 04:31 AM
Updated by: