
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2017 01:34 PM
Hi All,
I'm trying to work out how to put some styles onto the HR Case 'state' field when the state is 'Suspended' — but I also want to have a different colour based on the new date field I created 'u_suspend_till'.
What I want to achieve is the following:
- If the date is in the future — upto a day from today colour it green
- If the date is today — colour it yellow
- If the date is yesterday or older colour it red
I have setup 3 styles as per below, but I can't seem to get it working correctly — Any ideas what I'm doing wrong?
javascript:current.u_suspend_till = gs.daysAgo(1) && current.u_suspend_till != "";
background-color:yellow
javascript:current.u_suspend_till > gs.daysAgo(1) && current.u_suspend_till != "";
background-color:green
javascript:current.u_suspend_till > gs.hoursAgo(-1) && current.u_suspend_till != "";
background-color:tomato
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2018 12:29 PM
Hi All,
Update to this as I got it working. It was too much to code each individual style record, so I had to create a Script Include' to do the calculations and call this from my Field Style record.
Script include is:
var OpusHRfieldStyle = Class.create();
OpusHRfieldStyle.prototype = {
initialize: function() {
this.timeDiff = gs.dateDiff(gs.now().getDisplayValue(), current.u_suspend_till.getDisplayValue(), true);
},
//True if u_suspend_till is less than 1 day from now
redTime: function() {
return this.timeDiff <= 0;
},
//True if u_suspend_till is within 1 day from now
orangeTime: function() {
return this.timeDiff > 0 && this.timeDiff < 86400;
},
//True if u_suspend_till is more than 1 day and less than 21 days
greenTime: function() {
return this.timeDiff >= 86400 && this.timeDiff < 1814400;
},
type: 'OpusHRfieldStyle'
};
Each individual Field Style is then set as per below, calling the appropriate function:
javascript:new global.OpusHRfieldStyle().greenTime() && current.state == 24;
Then in the Style field I enter the required colour/style for the field - in my case it's 3 colours as per example below:
background-color:tomato;
color:red;
Now the field changes as needed based on the date field and the HR team is able to manage these much easier visually, see below
Hope this helps someone.
Cheers
Carl.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2020 11:40 PM
Servicenow oldwiki says:
"Returns: if boolean bnumericValue is true, the difference in number of seconds; if false, the difference in the format ddd hh:mm:ss."
I made two styles, one for one week and another for 1 day, looking like following:
background-color: Gold
javascript:(gs.dateDiff(gs.now().getDisplayValue(),current.current_version.u_valid_until.getDisplayValue(),true))<(7*24*3600);
background-color: Tomato
javascript:(gs.dateDiff(gs.now().getDisplayValue(),current.current_version.u_valid_until.getDisplayValue(),true))<(1*24*3600);
I do not know how (there is no Order field), but the later - "one day" - style prevails, even if both are true.
HTH 🙂