Have a true/false check on user table highlight user if checked

Justin Dirks1
Tera Expert

Hello, 

 

I am having issues with creating a checkbox on the user table that will highlight the user whenever they submit a ticket/task.  I wanted this to work similar to VIP field.  

 

Any help on this would be amazing. 

 

Thanks!

14 REPLIES 14

 

Hello @Justin Dirks1 

 

Just made few changes in your script - 

 

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

    if (isLoading) return; // Prevent execution on form load

    

    var callerLabel = document.querySelector('label[for="caller_id"]');

    var callerField = document.getElementById('sys_display.incident.caller_id');

    

    if (!callerLabel || !callerField) return;

   

    if (!newValue) {

        callerLabel.style.backgroundImage = "";

        callerField.style.color = "";

        return;

    }

    

    g_form.getReference('caller_id', vipCallerCallback);

}

 

function vipCallerCallback(caller) {

    var callerLabel = document.querySelector('label[for="u_monarch_vendor"]');

    var callerField = document.getElementById('sys_display.incident.u_monarch_vendor');

 

    if (!callerLabel || !callerField) return;

   

    // Check for VIP status

    if (caller.u_monarch_vendor === 'true') {

        var bgPosition = "95% 55%"; 

        if (document.documentElement.getAttribute('data-doctype') === 'true') {

            bgPosition = "5% 45%"; 

        }

 

        callerLabel.style.backgroundImage = "url(images/icons/vip.gif)";

        callerLabel.style.backgroundRepeat = "no-repeat";

        callerLabel.style.backgroundPosition = bgPosition;

        callerLabel.style.paddingLeft = "30px";

        

        callerField.style.color = "red";

    } else {

        callerLabel.style.backgroundImage = "";

       

callerField.style.color = "";

    }

}

 

Please try this. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw

NeEISQCY

when I tried to run that script I am getting this error.

Hello @Justin Dirks1 

 

Please modify it with the column names you have in your user table. I have given it caller_id from incident table, hence it's giving this null error because it's not getting this field to begin with. 

 

But I am wondering why are you applying this in caller_id field ? Like this every record in incident table will have the caller id field highlighted. 

 

You wanted it for user table name field right ? If the user has created any tasks or ticket then their name should have configured style in the "User" table, this styling shouldn't have anything to do with the incident table. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

ForrestGunk
Tera Contributor

You may want to check the Field Style[System UI > Field Style.

 

https://<YOUR_INSTANCE>.service-now.com/sys_ui_style.do?sys_id=9ab364de4a362304002c5f90e1814462&sysparm_record_target=sys_ui_style&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=valueCONTAINSvip%5EORDERBYname

 

if you have created a custom field as identifier , you need to specify that in the Value field

for example javascript&colon;current.caller_id.my_custom_field== true

then for the Style you can put something like "background-color: gold;"

 

Alvin24_0-1742406824485.png

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Justin Dirks1 

so are you saying the checkbox should highlight similar to VIP flag if the user has an active task associated to it?

for your client script to run as it involves DOM manipulation, ensure Isolate Script field = False

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader