How to compare date range in field styles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2017 11:27 AM
Hi Experts,
I am trying to build a query that if due date is between today and tommorow , then that record be shown with red color.
doing this in System UI ---> Field Styles
Came up with this condition
javascript: gs.dateDiff(gs.now(),current.u_due_date.getDisplayValue(), true) > 0
but not able to setup for range between today and tommorow.
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 01:58 AM
Hey,
can`t you just change your string to:
javascript: gs.dateDiff(gs.now(),current.u_due_date.getDisplayValue(), true) < 86400
So if the difference between both values is less than 86400 seconds (24 hours) it`ll return true, meaning th due date will be (b)reached within the next 24 hours.
I had some similar but more comlicated szenario and ended up with creating a script include which works fine but only does the coloring in list view and not on the form.
Luckily for my case that was not an issue at all as list view was the main concern.
Maybe this helps.
Cheers!
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 02:42 AM
deepanshanand wrote:
Hi Experts,
I am trying to build a query that if due date is between today and tommorow , then that record be shown with red color.
doing this in System UI ---> Field Styles
Just bear in mind that data operations client-side are problematic, since dates are presented as text and are subject to the user's locale plus preference settings, so there's no consistency between the different ways in which they're set.
An alternative is to have a BR that performs the date check then can show some icon or logo next to the date (like the VIP flag) - i.e.: do the date check server side, then pass something via the scratchpad to display the results client-side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 03:01 AM
I wrote a script include
function ColorSetting()
{
var updDate = new GlideDateTime(current.u_due_date);
var now = gs.nowDateTime();
if((updDate==now)||(updDate>=now.addDaysUTC(1)))
{
return true;
}
}
and then trying to call it on styles by putting javascript:ColorSetting();in value field
but not getting expected results
any idea where i am going wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 03:17 AM
I ended up with something like this in the script include earlier:
var now = new GlideDateTime();
var dt = new GlideDateTime(current.approval_request_timestamp);
now.addSeconds(-86400); // Substract a day from now
// gs.info(current.number+':: '+now+' NOW --- DT '+dt);
// gs.info('New: '+now.compareTo(dt));
if (dt!='' && current.hr_approval_timestamp=='' && dt.compareTo(now)==-1) {
return true;
} else {
return false;
}
Maybe this points to the right direction?
From my experience working with dates is really a pain due to different get & set / display /timezone etc. values for the reasons Dave mentioned 🙂
Martin