Someone can help me with a UI Policy onCondition to create script to target an specific country?

Leni Lunderman1
ServiceNow Employee
ServiceNow Employee

Hi everyone.

Could someone help me with an onCondition( ) script inside UI Policy? Since I cannot dot walk using the GUI to > Country Code = 'Canada'.

 

I will need to write a script that does the following:

If the country code is 'Canada', make the field "interior" and "exterior" visible and mandatory.

 

These two fields will be available only for users in Canada.

Thank you.

 

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@Leni Lunderman1 You can do dot walk in UI Policy. Follow below steps

1) Select table as "sn_hr_er_case (Employee relations)"

2) In the "When to apply" section, select "Show Related Fields"

 

SANDEEP28_0-1692770526141.png

 

3) Again click on same dropdown and Select "Subject Person --> User fields"

 

SANDEEP28_1-1692770645366.png

 

4) Again click on same drop down and This will allow you to select subject person user record fields.

 

SANDEEP28_2-1692770724519.png

 

Select country code field and its value

 

SANDEEP28_3-1692770807348.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

 

 

 

View solution in original post

7 REPLIES 7

Harish Bainsla
Kilo Patron
Kilo Patron

var countryCode = g_form.getValue('country_code');

if (countryCode == 'Canada') {

g_form.setDisplay('interior', true);
g_form.setMandatory('interior', true);
g_form.setDisplay('exterior', true);
g_form.setMandatory('exterior', true);
} else {

g_form.setDisplay('interior', false);
g_form.setMandatory('interior', false);
g_form.setDisplay('exterior', false);
g_form.setMandatory('exterior', false);
}

 

please mark helpful if its work

Unfortunately, it didn't work. The field is still available for every user, no matter the country.

 

You need to put the condition in the 'When to Apply' section. Then put those script from above in Execute if true and Execute if false on 'Script' tab.

 

Or you can simply create an onchange client script for this.

SANDEEP28
Mega Sage

@Leni Lunderman1 Do you want country code of logged in user or is there any field on form which contains user ID ?

Also are you trying to refer country code which is present in Sys_user table ?