- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-15-2019 02:09 AM
Hi,
I wish to achieve conditional styling based on a date field, but I am struggling with the syntax for the code;
- I have a custom date field in a scoped application (called avventer_svar_innen)
- I want to add styling (somewhere) based on the date field (e.g. if the date is passed: make some field red)
- Mission: get my date field, get todays date - compare the two. Should be easy enough, but I am having no luck.
I have achieved some conditional styling based on other criteria, as posted by Manjul here. I have also learned that I need to use GlideDate.subtract (and not gs.dateDiff) as this is a scoped application.
Here is one thing I tried, which I thought would to the trick, but no luck:
Javascript: if (GlideDate.subtract(new GlideDate().setValue(current.avventer_svar_innen), new GlideDate()).getDayPart()) < 0;
What am I missing here? Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-18-2019 05:07 AM
Hi,
The suggested code didn't work for me, but I got it working with this code:
javascript: GlideDateTime.subtract(new GlideDateTime(current.avventer_svar_innen), new GlideDateTime()).getDayPart() > 0;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-15-2019 02:34 AM
Hi,
use this and it will work; I have applied the color to same field i.e. the date
you can give your custom field as well;
I can apply color to Field1 based on the Date value as well
give value as below
javascript: new GlideDateTime(current.avventer_svar_innen) < new GlideDateTime()
I tested this in my scoped app table and it is working on list
Mark ā
Correct if this solves your issue and also mark š Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-18-2019 05:07 AM
Hi,
The suggested code didn't work for me, but I got it working with this code:
javascript: GlideDateTime.subtract(new GlideDateTime(current.avventer_svar_innen), new GlideDateTime()).getDayPart() > 0;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-15-2019 02:44 AM
Hi, you need to use setDisplayValue and it will work. I tried in background script and this is working fine.
Javascript: var gd = new GlideDate(); gd.setDisplayValue(current.avventer_svar_innen);
if(GlideDate.subtract(gd,new GlideDate()).getDayPart()) <0
Mark the comment as a correct answer and helpful once worked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-18-2019 05:09 AM
Thanks for the replies! I didn't get it to work with the suggested code, but I have added the code that worked for me in my reply above.