UI Policy not working as expected

Noor Mohammad1
Kilo Guru

UI policy "Clear the variable value" makes a field empty even the condition is false in Catalog items.

I've created a catalog item with several variables, then added UI policy to show and require some variables based on answer to a previous question.

  • "Applies on Requested Items" is checked on UI Policy
  • UI Policy Action is configured as follows: 

 

NoorMohammad1_0-1666516679677.png

 

It works fine in service portal, but then on requested item view the value is empty (it should include user's answer).

It works if I uncheck the 'Clear the variable value', but I want it to be cleared when user selects something else... Is there any other way to make it work?

1 ACCEPTED SOLUTION

Noor Mohammad1
Kilo Guru

for some weird reason UI policies were impacting when onload is checked so UI policy script was added to fix it where clear variable value is required.

View solution in original post

6 REPLIES 6

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Noor Mohammad1 

 

Hope that 'UI Type' field on UI Policy is 'ALL".

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

I don't see such kind of field on the ui policy but in the xml its value is set to 0.

My ui policy applies to 

NoorMohammad1_0-1666523579173.png

 

I think UI type field is visible only when run script is selected where you select the desktop or all option.

this is related to UI Policy action where the value is set to true for clear value and the user input is not visible on the backend.

Pavankumar_1
Mega Patron

Hi @Noor Mohammad1 ,

you can check Applies on Requested Items on UI policy form. If still not working try below.

You can use the onchange catalog client on you are variable and UI type should be All and use below script.

If it is not helpful share the exact conditions I will help you.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue != '') { //you can give value and clear based on the value
        g_form.clearValue('variablename'); //add your variable that need to clear 
    }
}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

Hi @Noor Mohammad1 ,

If your issue got resolved close the question by Accepting solution and hit thumb icon.

If not reply and share the details.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar