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

Not applicable

Hi,

Can any one share the style code. How to change field's color ?


Malaya
Giga Expert

assuming it's a table then u can use below for cell color. template.print("");


Hlo,

 

In the style field, you have to write like - background-color:red; or any other color name you want to display.

Code in the Value field can be like this-

javascript: gs.dateDiff(current.opened_at.getDisplayValue(), gs.now().getDisplayValue(), true) < 15000;

Method is - javascript: gs.dateDiff(String startDate, String endDate, Boolean numericValue);

This method expects the earlier date as the first parameter and the later date as the second parameter; otherwise, the method returns the difference as a negative value. Use getDisplayValue() to convert the strings to the expected format.

Here, Earlier date = current.opened_at.getDisplayValue() AND later date is gs.now().getDisplayValue()

 

 Regards,

Shubham