Compare a Date Field with the Current Servicenow Date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 02:04 PM
Hi Experts,
I am trying to Compare a Date Field with the Current Servicenow Date.
The Date field is called "u_end_date" and it is just a Date Field, not a Date Time Field.
So right now I am just trying to compare the Date field with the Current Servicenow Date to send a message, if these dates are the same just send an info message that the dates are the same. I did a business rule but is not working.
This is the business rule code:
var now = gs.now();
var end = current.u_end_date;
if (now == end){
gs.addInfoMessage( now + "=" + end);
}
I did a test before, with out the if condition to see the values of both and I see that the order of the values are different.
I think my code is not working because the order of the values.
Do you have any Idea why my code is not working?
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 02:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 03:02 PM
The only way I have seen date comparison works is by using glide datetime.
Try this
var now = new GlideDateTime();
var end = new GlideDateTime(current.u_end_date);if(now.getDate() == end.getDate()){
gs.addInfoMessage( now + "=" + end);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2017 03:14 PM
Hi dvp,
I tested your code and still not showing the message.
Actually before this code that I am sharing here, I tried to do with GlideDateTime() and tried to get de date by getDate() but when I tested I realize that the "now" variable appears in the info message as null.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2017 12:04 AM
That wont work.. putting only a date "2017-03-03" into GlideDateTime will reslut in "2017-03-03 00:00:00" meaning if you don't do the comparing exactly at this time it won't match the the "new GlideDateTime".
//Göran