Field Style using JavaScript Value for dot walked field that is not empty

Leslie Hochszt1
Giga Contributor

I am trying to use a System UI > Field Styles on the Requester field on the Incident form.  We have added a string field called Special Handling to sys_user.  I am trying to use JavaScript in the Value field.  If the Requester's Special Handling field is NOT empty, I want the Requester field background color to turn yellow. I have tried a number of variations in the value field including the following, but have been unsuccessful:

javascript: var answer = !current.caller_id.u_special_handling.nil(); answer;

javascript: var answer = current.caller_id.u_special_handling != ""; answer;

javascript: var answer = current.caller_id.u_special_handling != NULL; answer;

javascript: current.caller_id.u_special_handling != ""

Etc etc!

Anyone have any ideas? Thank you! 

Leslie

4 REPLIES 4

Phuong Nguyen
Kilo Guru

Hi Leslie,

Per the ServiceNow doc, the value field only affects the list field styles https://docs.servicenow.com/bundle/madrid-platform-administration/page/administer/navigation-and-ui/... 

I am afraid you will need to use client script instead, this post might be helpful for you: https://community.servicenow.com/community?id=community_question&sys_id=55a10b69db98dbc01dcaf3231f96...

Regards,

Phuong

If you find my suggestions helpful, please mark it as correct or helpful to help out others as well 🙂 

The doc article you posted lists that it should be available for the form, not just the list: "Field styles allow you to declare individual CSS styles for a field in a list or form."

I considered using a client script, but the below message comes up on client scripts, so I'd rather not go against best practice:

New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false.

 

If you scroll down to the Procedure part, you can see that it says "Note: The value only affects list field styles. To apply field styles on both lists and forms, leave this field blank."

Regards,

Phuong

If you find my suggestions helpful, please mark it as correct or helpful to help out others as well 🙂 

vkachineni
Kilo Sage
Kilo Sage

Can you create a script include and try this.

Make sure the script include is accessible to all scopes and marked client callable (may be).

 

javascript:  var answer = new IncidentUtils.callerHasSpecialHandling(current.sys_id);  answer;

 

in the function you can get the caller and check the special notes field. return a true or false (boolean).

you can also test your script as a background script.

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022