Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

field conditional formatting

georgechen
Kilo Guru

Hi folks

I am having an issue setting up a cell format right, here is the style

Table: sys_user

Field Name:   u_email_status

Value: javascript: current.u_email_status=='1'

Style: background-color: red;

the u_email_status is a string field based on sys_user table, with a choice list of the following options

Valid Email:0
Invalid Email:1
Do not send:2

This condition is not working, but if I leave the value field blank, the field formats as RED, so I think the value has some issue with it.

Troubleshooting steps:

javascript: current.u_email_status=='1', no luck

javascript: current.u_email_status==1, no luck

javascript: current.u_email_status=='Invalid Email', no luck

javascript: answer = current.u_email_status=='1'; answer, no luck

Any advise would be appreciated.

1 ACCEPTED SOLUTION

Hi George,



Here is how I would try to get the styles for any table field on the Form and also on the list view:



My field name is : "u_email_status" and the sys_choice are as follows:


Screen Shot 2015-12-15 at 8.29.21 PM.JPG



The styles are written as:



Screen Shot 2015-12-15 at 8.27.50 PM.JPG



Also,


Screen Shot 2015-12-15 at 8.40.55 PM.JPG



The list view looks something like this:


Screen Shot 2015-12-15 at 8.26.03 PM.JPG




The Client script to get the color on the form is written as:


Screen Shot 2015-12-15 at 8.27.10 PM.JPG





The form looks something like this, when the [Valid Email = 0]


Screen Shot 2015-12-15 at 8.26.20 PM.JPG




Hope this help!


-Manjul


View solution in original post

11 REPLIES 11

i found this mixed with a onChange client script allowed a async update to the colour if changed on screen for users which UX designers would love:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (newValue != oldValue) {


          return;


    }


  var color = g_form.getControl('yourfield');


  if(color.options[color.selectedIndex].value == "option1"){


  color.style.backgroundColor = "green";


  }


  if(color.options[color.selectedIndex].value == "option2"){


  color.style.backgroundColor = "red";


  }


  if(color.options[color.selectedIndex].value == "option3"){


  color.style.backgroundColor = "yellow";


  }


  if(color.options[color.selectedIndex].value == "option4"){


  color.style.backgroundColor = "grey";


  }


  if(color.options[color.selectedIndex].value == "option4"){


  color.style.backgroundColor = "pink";


  }


  if(color.options[color.selectedIndex].value == "option4"){


  color.style.backgroundColor = "orange";


  }


}


Thanks David for sharing!