onLoad client script to check the condition & set field background colour

rishabh31
Mega Sage

Dear Community Members,

 

I am stuck in setting the background colour for the reference caller field in the 'List view of Agent workspace', which requires a condition to check whether the 'Caller (caller_id)' of the respective incident is 'VIP' or Not, if 'VIP' then display a 'Red' background colour on 'List View of Agent Workspace'. if false (i.e., Not VIP) then NO need to display any colour & keep the caller field as it is.

For this, created an onload CS on Incident table, View- workspace (Global-false), UI type- All, Isolated script- check, 

 

Script- 

function onLoad() {
    g_form.getReference("caller_id", checkIfVIP);

    function checkIfVIP(user) {
        if (user.vip == "true")
            g_form.getElement("sys_display.current.caller_id").style.backgroundColor="orange";
        else
            g_form.getElement("sys_display.current.caller_id").style.backgroundColor="white";
    }
}

 

Requesting to pls correct my script to achieve the requirement.

 

Expecting that soon I will mark the solution Helpful & accepted!

 

Thanks in advance 

1 ACCEPTED SOLUTION

BharathChintala
Mega Sage

@rishabh31 

1. Right click on the caller field

 

2. go to Configure Styles.

 

3. Click on "New"

 

4. Select table where the field belongs.

 

5. Select the "Color" field in the Field name drop dow box.

 

6. In the Style field write this line: background-color:orange;

 

7. Submit.

 

also refer to this document page : 

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/workspace/task/highlig... 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

3 REPLIES 3

BharathChintala
Mega Sage

@rishabh31 

1. Right click on the caller field

 

2. go to Configure Styles.

 

3. Click on "New"

 

4. Select table where the field belongs.

 

5. Select the "Color" field in the Field name drop dow box.

 

6. In the Style field write this line: background-color:orange;

 

7. Submit.

 

also refer to this document page : 

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/workspace/task/highlig... 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Dhruv Chandan
Giga Guru

Hi,

 

There are some issues with the code :-

 

1. The "getReference", is not a best practice to use. Instead i would recommend to use a GlideAjax call which works in sync with Script include.

Example of GlideAjax: https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet/ta-p/2312430

 

2. After writing the custom code mentioned in point 1, you could use the below code to fill color in reference type of field :-
g_form.getDisplayBox('caller_id').style.backgroundColor = 'orange'

 

Hope this helps!

 

Regards,

Dhruv