change color on due date field when approaching due date and expired

Nic Omaha
Tera Guru

Sorry I know this is probably a simple question but how do I get the Due Date field on Request, and Item in Service Catalog to turn yellow if its say 2 days before due date and red if its on or past the due date?

 

req due date field.JPG

item due date field.JPG

13 REPLIES 13

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


tltoulson
Kilo Sage

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


Brad Tilton
ServiceNow Employee
ServiceNow Employee

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/


dineshkumarmogu
Kilo Explorer

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