Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Policy to hide Choice Value based on something another field contains

Joshuu
Kilo Sage

Hi All,

I have a field on incident form as "follow up status" which is having 4 choices as below.

find_real_file.png

So, whenever this field changes to New, In progress and On Hold the incident state "Resolved" should be hidden.

find_real_file.png

I have tried the following UI Policy. It is working when the followup status is (New/In Progress/On Hold), I am able to hide the resolved choice from incident state without saving the form. If I save the form I can see the resolved state as normal.

And also it should be visible when the follow up state is completed. That is also not working. 

UI Policy condition:

find_real_file.png

Script in UI Policy:

find_real_file.png

 

Please correct me If I am wrong.

 

Thank you,

Priya.

 

1 ACCEPTED SOLUTION

Hi DVP,

I have set on load to TRUE, it is working for New, In Progress and On Hold.

But when it comes to completed it is working only when I change the follow up status from None to completed. It is not working when I change it from New to Completed, In progress to Completed, On Hold to Completed.

please suggestion what is wrong in this..

 

Thank you,

Priya. 

View solution in original post

8 REPLIES 8

Surabhi5
Kilo Contributor

Hi All,

 

I have a requirement to restrict the problem closure based on role (problem manager) and group(with a prefix "xyz").

I was able to achieve this requirement partially i.e. for the role the restriction has been updated and works fine using below code. How do i add another condition to it for the second part i.e. group with prefix?

Any help would be really appreciated.

var isPrbMan = g_user.hasRole('Problem Manager');
if (!isPrbMan)
g_form.removeOption('state','6');
else if (isPrbMan) {
return;
}

 

This i am trying using client script, is there a way i can do it using UI policy where i can put a restriction on both role and group with prefix?

 

Regards,

Surabhi

Kunal Varkhede
Tera Guru

Hi priyarao,

 

You can write Execute if false block script section

g_form.addOption('Incident_state','6');

 

And

 

Set OnLoad is True in When to apply section. 

(If onLoad() is true it will work on both onLoad() and onChange() of form).

 

Please Mark Correct/Helpful answer if it helps you.

Regards,

Kunal.

 

 

 

Thanks Kunal 🙂

Edxavier Robert
Mega Sage

Hi @Kunal Varkhede, @priyarao, @dvp 

I am currently working on a similar requirement with a UI Policy. I am trying to restrict a choice option if the user that is making the request have a field check. Name of the field is u_employee_mall on the sys_user table. I tried with different scripts and so far this one below works but only thru the Service Portal and thru the legacy view. 

function Load() {
    var gr = new GlideRecord('sys_user');
    gr.get(g_user.userID);
    gr.query(response);
    function response(gr) {
        while (gr.next()) {
            var MallEmp = gr.u_mall_employee;
            if (MallEmp == 'false')
              // Type the name of the field and then the choice to remove
              g_form.removeOption('request_type', 'Microsoft Teams Softphone');
            
              else {
		alert('You are not an employee mall');
            }
        }
    }
}

This only works thru the ServicePortal and not thru the legacy view. I got the script to run on all

find_real_file.png

Any idea?