UI policies

pallavigaik
Kilo Guru

Hi All,

pallavigaik_0-1779721459481.png

 

I have configured UI policies to make fields visible, read-only and mandatory. But it's not working as expected.

 

Requirements:

  1. If Use main address as mailing address is set to false, then show address related fields (address search, can't find address, street, street number, suburb, state, post code, country). Else it should be hidden.
  2. All address related fields should be mandatory.
  3. If can't find address is set to true, then address related fields should become editable, mandatory. (A search is implemented on address search field. If we search any address and select any of the address, it inserts values in address related fields).

    If can't find address is set to false, then address related fields should be read-only, mandatory

Currently working functionality:

  1. If Use main address as mailing address is set to false, then address related fields are visible. Else it is hidden
  2. If can't find address is set to true, then address related fields becomes editable, mandatory. Address search is non-mandatory.
  3. If can't find address is set to false, then address related fields becomes read-only. Address search is mandatory.


Issue:

  1. If can't find address is false, then address related fields are not coming as mandatory. it should be mandatory always.

 

Please help me to fix this issue. 

1 REPLY 1

Tanushree Maiti
Giga Patron

Hi @pallavigaik 

 

Try this:

 

  1. a. UI Policy 1: Show/Hide Address Fields

Condition: Use main address as mailing address is false

b.Under the UI Policy Actions, set the following fields to Mandatory: True and Visible: True

  • Address Search
  • Can't Find Address
  • Street
  • Street Number
  • Suburb
  • State
  • Post Code
  • Country
  1. Note: Set the policy to "Reverse if false" so that these fields automatically hide 

 

  1. onChange Client Script: Manage Editability and Mandatory Rules
  • Type: onChange
  • Field Name: cant_find_address

 

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue === '') {

        return;

    }

    if (newValue == 'true' || newValue === true) {

          g_form.setReadOnly('street', false);

        g_form.setReadOnly('street_number', false);

        g_form.setReadOnly('suburb', false);

        g_form.setReadOnly('state', false);

        g_form.setReadOnly('post_code', false);

        g_form.setReadOnly('country', false);

    }     

    else {

        g_form.setReadOnly('street', true);

        g_form.setReadOnly('street_number', true);

        g_form.setReadOnly('suburb', true);

        g_form.setReadOnly('state', true);

        g_form.setReadOnly('post_code', true);

        g_form.setReadOnly('country', true);

    }

 

}

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: