Change colour of field style based on date comparison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2009 08:48 AM
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
- Labels:
-
Problem Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2010 05:31 AM
Hi John
Ah... Seconds... x60 x60 x24 and it works like a charm
Thanks and season's greetings,
Christian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2011 11:28 AM
This works great, but changes color for all tickets. I would like to exclude tickets that are not active. Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2019 09:12 AM
Hi FR16,
The color is changing for all tickets because 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 and ultimately gives bad results.
I was facing same issue. Now, It worked for me.
javascript: gs.dateDiff(current.opened_at.getDisplayValue(), gs.now().getDisplayValue(), true) < 15000;
Here, Earlier date = current.opened_at.getDisplayValue() AND later date is gs.now().getDisplayValue()
Use getDisplayValue() to convert the strings to the expected format.
javascript: gs.dateDiff(String startDate, String endDate, Boolean numericValue);
Regards,
Shubham
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2011 11:45 PM
Hi Andrew,
It works great, and i used gs.nowNoTZ() as i have only the date feild. I need your help in removing the style if the ticket is closed/Resolved. Any ideas of how to change or removed this style once the ticket is Resolved or False.
Thanks
Ajay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2011 03:35 AM
Guys i got the solution. I got it from Demo site from projects moduel
javascript:((current.due_date.getGlideObject().compareTo(new GlideDateTime()) < 0) && current.u_work_end.nil());
As i was in a diffrent module i used diffrent feilds...
in place of due date i have "expected completion date"
in place of work end i made "closed_at.nil();
So here if you want to remove the style after the ticket is resolved you have two ways to do it.
1. Create a new actual work end date feild and make that as that feild and end condition.
2. if you use the closed_at to track the closing time use this as the end condition.
Thanks
Ajay Kumar Anugu