change color on due date field when approaching due date and expired
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2014 08:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2017 03:26 PM
Sorry to necro an old thread, but I thought this might add some value.
I tried using your code example, but it wasn't working for me. What I found was that gs.now() was pulling the system time in UTC, not the timezone of the user. To get around this, I used the following as my field style value:
javascript: gdt = new GlideDateTime; (gs.dateDiff(gdt.getDisplayValue(), current.u_last_actioned.getDisplayValue(), true) * 1 ) < -172800
What I'm doing here is I'm setting gdt as a new GlideDateTime object and then using the getDisplayValue method to grab the current date and time based on the user's timezone. I then use the same gs.dateDiff function as the original example.
You may notice that I've also made my two-days-as-seconds value (172800) as a negative. This is because I was wanting to check against a date in the past, not a date in the future like a due date. I'm using a custom field called u_last_actioned. You could replace that with your own date/time field.
Hope this helps someone!
Cheers
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2014 08:46 AM
Hi Nicholas,
For additional information, you can refer to the wiki:
Defining Field Styles - ServiceNow Wiki
And the following covers a great example of how to use javascript for advanced styles for Due Dates: Defining Field Styles - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2014 08:49 AM
In addition to the wiki links provided here's another explanation of field styles.
http://www.cloudsherpas.com/partner-servicenow/servicenow-tech-tuesdays-list-field-styles/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2015 12:09 AM
Hi Nicholas,
We have the similar requirement, but we need to highlight the stage to be yellow, when it is in requested state. Can you please help me on how to achieve this.
Regards,
Dinesh