- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2016 07:02 PM
Hey folk,
I have a requirement where I need to notify users about an upcoming renewal date.
So, I have a GlideRecord that has a renewal date field that is a GlideDate.
I need to run a daily scheduled job that will check each record in the table, to see if any of the renewal fields are less than 30 days away.
I presume I can use 1000*60*60*24*30 to get the 30 day duration in milliseconds.
Also, I presume I can use gs.now() to get the current date.
1) How can I subtract 30 days from this GlideDate renewal date and properly compare it to today's date?
2) Or how can I add 30 days to today's date and compare it to this GlideDate renewal date?
3) Or perhaps I should do the comparison, then compare it with 30 days?
I could use the community's help in figuring out what the best practice is for doing the above in Fuji... bit rusty on the date comparison.
Thanks,
D
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2016 07:27 PM
It is very easy by setting the filter on your list first and then copy the query and use an addEncodedQuery()
Go thru section 3 in this link
Encoded Query Strings - ServiceNow Wiki
Here I am setting a filter for all the records that have Cab date 30 from now.
Once you set the filter, copy the query as shown
Now use it in the Encoded query as shown below
gr.addEncodedQuery('cab_dateRELATIVEEE@dayofweek@ahead@30');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2016 07:27 PM
It is very easy by setting the filter on your list first and then copy the query and use an addEncodedQuery()
Go thru section 3 in this link
Encoded Query Strings - ServiceNow Wiki
Here I am setting a filter for all the records that have Cab date 30 from now.
Once you set the filter, copy the query as shown
Now use it in the Encoded query as shown below
gr.addEncodedQuery('cab_dateRELATIVEEE@dayofweek@ahead@30');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 11:19 AM
Thanks Abhinay! That's definitely the most straightforward and clean approach!! (I should have thought of it haha)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2016 08:10 PM
You can do this Date comparison with gs.dateDiff(): GlideSystem Date and Time Functions - ServiceNow Wiki
var diff = gs.dateDiff(gr.u_some_date_field.getDisplayValue(), gs.nowDateTime(), true); // returns seconds
var thirtyDays = 2592000; // Thirty days in seconds
if (diff < thirtyDays) {
// send notification
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2016 11:58 AM
It is very useful. I use this almost all the time. You do not need to worry about how complex your conditions could be, because ServiceNow will take care of everything for you by converting it to a query.