Using Syle to highlight a field

amacqueen
Mega Guru

The picture below shows what I've done to get a field highlighted based on the fields value

Style.PNG

I have a feeling that I may have got the syntax wrong as this field is a string and not an integer/choice field.

I would welcome any feedback.

TIA

1 ACCEPTED SOLUTION

Angus,


Use the below code:



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


  var cTypeLabel = $('label.incident.contact_type');


  var cTypeField = $('incident.contact_type');



if (newValue == 'Self Service') {


  cTypeLabel.setStyle({backgroundColor: "red"});


  cTypeField.setStyle({color: "red"});


  }


  else {


  cTypeLabel.setStyle({backgroundColor: ""});


  cTypeField.setStyle({color: ""});


  }



}


View solution in original post

30 REPLIES 30

Create a onChange client script on Contact type to change the background color of the value when "Site Surgery" is selected.



You can modify "Highlight VIP" client script on Incident.


amacqueen
Mega Guru

Thanks to all for yesterday's input.


The field I need to change the style of is on a form so I have been playing with a Client Script but it's not working. I'm sure it's my code that's wrong but not being a coder I can't work out the correct syntax. Also I identified I couldn't dot walk in a Client Script and as the original field is on the task table I've tried to take that into account. Here is what I have got so far:-



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




      //wait until there is a valid record in the field


      if (newValue) {




          var type = g_form.getReference('task.contact_type');


          if (type = "Self Service")




              //change the contact type label to red background


              document.getElementById('label.task.contact_type').style.backgroundColor='red';




              document.getElementById('sys_display.taskcontact_type').style.color='red';


          }


}



Thanks


Angus,


Use the below code:



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


  var cTypeLabel = $('label.incident.contact_type');


  var cTypeField = $('incident.contact_type');



if (newValue == 'Self Service') {


  cTypeLabel.setStyle({backgroundColor: "red"});


  cTypeField.setStyle({color: "red"});


  }


  else {


  cTypeLabel.setStyle({backgroundColor: ""});


  cTypeField.setStyle({color: ""});


  }



}


As 'Contact Type' is inherited form Task should the code change to reflect that? I've tried your suggestion and also tried it with task replacing incident but neither works unfortunately.



Below is my script, having changed it back to your suggestion:-



find_real_file.png


Eventhough 'Contact Type' is inherited from Task table, it is available for Incident table which extends task table. In Table change it to Incident.



Are you on Eureka or Fuji? I tested in Eureka and it works fine.