How to configure a UI policy to hide a field on task on extended tables?

aansell
Mega Expert

Hi,

I am trying to create a UI Policy to hide the Task table filed 'time_worked' when users who do not have the role 'timecard_user' are looking at Requests.

Unfortunately the UI policy doesn't work when the specified Table is 'Task' (although it does work when the specified table is 'Request') can anyone advise what is wrong with the condition (see screen-shot) or my script?

Thanks,

Arthur

------------------------------------------------------------------------------------

function onCondition() {

// we only want users in the group 'Time Card Users' to see this field

if (g_user.hasRole('timecard_user')) {

                  g_form.setDisplay('time_worked', true);    

}

//Non 'Time Card Users' we dont want to see the field

          else

                  g_form.setDisplay('time_worked', false);

        }

1 ACCEPTED SOLUTION

preddy
Kilo Guru

Hi Arthur,



Can you please enable the Inherit checkbox in UI policy. This will applies to the extended tables also.



Please hit like or mark the response as helpful or correct based on the impact!


View solution in original post

11 REPLIES 11

dravvyramlochun
ServiceNow Employee
ServiceNow Employee

Hello Arthur,



Maybe the following might be helpful.



UI policies

UI policies are client-side logic that governs field behavior and visibility on forms.


ServiceNow automatically generates client-side Javascript that the browser executes to enforce policies on the form being displayed. Each policy has a condition that must resolve as true to be executed. Policies determine the following field attributes and behaviors:


  • Make the field mandatory
  • Show or hide the field
  • Make the field read-only

Most basic UI policies are declarative and do not require scripting. You may also write your own scripts to handle more complex scenarios.In the example below, no scripting was required to:


  • Make the Number field read-only
  • Make the Configuration item field mandatory
  • Hide the Priority field
Figure 1. Before and after UI policy applied


Note: Another client-side script within ServiceNow, called a client script, can also be used to hide/show fields and make fields mandatory. For faster load times, use a UI policy instead of a client script when the only purpose of the script is to set a field to show/hide, read/write, or mandatory/optional.



Reference: https://developer.servicenow.com/app.do#!/training/article/app_store_learn_dev_platform_intro_helsin...



Thanks,


Dravvy




Please Hit like, Helpful or Correct depending on the impact of the response


Hi Dravvy,



The background info has been very useful.



Thanks,


Arthur


preddy
Kilo Guru

Hi Arthur,



Can you please enable the Inherit checkbox in UI policy. This will applies to the extended tables also.



Please hit like or mark the response as helpful or correct based on the impact!


HI Pavan,


Thanks for pointing that out, it's much appreciated.



Best regards,


Arthur