Change colour of field style based on date comparison

andrewnorris
Giga Contributor

Hi

I'm trying to get the due date field text on the Problem form to change colour if the date is in the past.

I've created a field style for the field 'Due Date' on the Problem table to turn read if the following value is true:

javascript:gs.dateDiff(gs.nowDateTime(), current.due_date, true) < 0

However, this changes the colour for that field on every record whether or not it is in the past. Has anyone done something similar or can you see a glaring error in the comparison code above?

Thanks in advance,
Andrew

P.S. Our date format here is dd/MM/yyyy HH:mm:ss

12 REPLIES 12

andrewnorris
Giga Contributor

OK, I think I've cracked it.

javascript:gs.dateDiff(current.due_date,gs.nowDateTime(),true) > 0 ;

wasn't working because gs.nowDateTime() returns the current date/time in the user defined format but current.due_date is in a different date format

javascript:gs.dateDiff(current.due_date.getDisplayValue(),gs.nowDateTime(),true) > 0 ;

works as it returns current.due_date in the user defined format.


This works great, but changes color for all tickets. I would like to exclude tickets that are not active. Any ideas?


cdeclos
Mega Contributor

Hello Folks

I'm running into the same kind of issue and cannot find the right syntax to achie what I want.

Based on what is explained above, I'm trying to highlight requested items that have been updated within the 5 last days, so I created the following style:

Table: task
Fieldname: sys_updated _on
Value: javascript:gs.dateDiff(current.sys_updated_on.getDisplayValue(), gs.nowDateTime(), true) < 6
Style: background-color:tomato

Where did I do wrong ?

Christian


Code looks fine but dateDiff returns number of seconds so you'll need to increase the value of your check.