Change incident field style when comment is added

dp11
Tera Guru

Hi,

I am required to implement the following:

When a customer replies to an incident that is in a state of "Awaiting User Info", modify the color of the incident number to red.

So, I went to Field Styles and created a new style:

Table: Incident

Field: Number

Value: javascript: current.getValue('state') == '5' && current.comments.changes()

Style: background-color: red

The value of the state "Awaiting User Info" in our system is 5. But this does not work!

Can someone please tell me what I am doing wrong?

Thanks,

Debashree

1 ACCEPTED SOLUTION

ghsrikanth
Tera Guru

Actually your requirement is little tricky, because once the customer updates the Awaiting user info state incident, then the incident number should be highlighted so that customer support can go to that incident fast.


I will advice you to think of a design, because field styles may not work for .changes()


in your requirement you want the hightlight to stay on incident till the customer support acts on.


In this case, define a new field like checkbox, and on the basis of the field keep the color on the number



That checkbox can be updated by a before business rule which triggers when state = Awaiting user info and customer updates the comments


The business rule will make the checkbox (name it like Need Attention) checked


Now define field styles on this field


This will server your requirement fine





Hopefully it helps


View solution in original post

22 REPLIES 22

Thanks for your replies.


The list view works fine in Fuji. The state check works fine too. My issue is how to detect when the customer has replied….


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Debashree,



If that doesn't work then you should be able to achieve via client script.


http://www.servicenowguru.com/system-ui/field-styles-service-catalog-variables/


Thanks very much for your reply and the pointer. I will try to get this to work first and if it doesn't work then I will go with the solution provided by Srikanth Gunuru and update.


I wish your suggestion worked, as it would make life so much simpler. I don't know why either of the following client scripts would not work.



1. using the link you had provided: Field Styles for Service Catalog Variables - ServiceNow Guru


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


    if (isLoading || newValue == '') {


          return;


    }



    //Type appropriate comment here, and begin script below


      var elementID = g_form.getControl('number'); //Get the correct reference element


      elementID.style.backgroundColor = red;


}



2. using sample code by developers from the wiki: http://wiki.servicenow.com/index.php?title=Useful_Form_Scripts#gsc.tab=0 (Name: Change Form Color on State Change)


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


    if (isLoading || newValue == '') {


          return;


    }



    //Type appropriate comment here, and begin script below


      var elementID = gel("incident.number"); //Get the correct reference element


              elementID.style.backgroundColor = "red";


}



If anyone has any idea regarding how to make either of the above work please share.



Thanks,


Debashree


Actually I found the reason why the above client scripts do not work. My incident field is a Read Only field. If I set the background color using the System's Field Style there isn't any problem...works as expected. But for some reason the background color change would not take effect for read only fields. I have verified this. So bad luck for me. I will now try out the solution that Srikanth Gunur has suggested.