Apply Field Style to Any Value

tstocking
Tera Guru

Is it possible to apply a field style to any value of that field and not just a specific value?   If I leave the value field blank, the style doesn't apply.   If I enter a single value, then it applies but I would like to format the field with the field style all the time.   mlockhart

1 ACCEPTED SOLUTION

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Hi Todd,



Have you tried using a javascript in the "value" field, like explained on our wiki? In javascript you can add condition if value is empty (like for example "javascript: current.state == ''", where state is the field), but you'll have to test it.



Defining Field Styles - ServiceNow Wiki



Regards,


View solution in original post

7 REPLIES 7

Good idea Michael to have a field tell you the relative time it's been opened!   Figured I see if I can get this created.   Is your script similar to the one I came up with?



(function calculatedFieldValue(current) {




  // Add your code here


  var dateOpened = current.getDisplayValue('sys_created_on');


  var today = gs.nowDateTime();


  var difference = gs.dateDiff(dateOpened, today, false);



  return difference;   // return the calculated value




})(current);


Here's what we use. It's a Duration field with a calculated value as follows:



if (current.active == true){


    gs.dateDiff(current.opened_at.getDisplayValue(), gs.nowDateTime(), false);


  }



The "false" value at the end gives us the format "XX Days XX Hours XX Minutes".


How do you apply it when you dot-walk to that field on a report?