Add a reference qualifier in a UI Policy script to remove options from a reference field

Chris17
Tera Contributor

Hello,

I currently have a requirement to remove an option from a reference field. This is supposed to be removed when a UI policy triggers. I'm unsure if this functionality is possible.
find_real_file.png

find_real_file.png

 

The option im trying to remove still appears, see below:

find_real_file.png

1 ACCEPTED SOLUTION

-O-
Kilo Patron
Kilo Patron

It is not possible to remove options from a reference field as it does not have options. Only choice fields, or fields set to show as drop-downs (strings, integers) have options (that can be removed by scripting).

Reference fields use reference qualifiers to limit items that can be selected. In reference qualifiers one has the possibility to filter out items that could be selected in the pop-up window. In this case you would probably need to create a script based reference qualifier.

For the presented case, it would probably look like:

javascript: current.variables.user_location == '<value of Remote/Virtual>' ? 'name!=Global' : '';

assuming user_location_parent is a reference to cmn_location.

You should probably also add an onChange client script so that user_location_parent is cleared whenever user_location changes (maybe only when it changes to Remote/Virtual) - so that if the user switches away from Remote/Virtual, chooses Global as user_location_parent but than switches back to Remote/Virtual, the now invalid Global user_location_parent is cleared, forcing the user to select a new valid reference.

View solution in original post

8 REPLIES 8

-O-
Kilo Patron
Kilo Patron

It is not possible to remove options from a reference field as it does not have options. Only choice fields, or fields set to show as drop-downs (strings, integers) have options (that can be removed by scripting).

Reference fields use reference qualifiers to limit items that can be selected. In reference qualifiers one has the possibility to filter out items that could be selected in the pop-up window. In this case you would probably need to create a script based reference qualifier.

For the presented case, it would probably look like:

javascript: current.variables.user_location == '<value of Remote/Virtual>' ? 'name!=Global' : '';

assuming user_location_parent is a reference to cmn_location.

You should probably also add an onChange client script so that user_location_parent is cleared whenever user_location changes (maybe only when it changes to Remote/Virtual) - so that if the user switches away from Remote/Virtual, chooses Global as user_location_parent but than switches back to Remote/Virtual, the now invalid Global user_location_parent is cleared, forcing the user to select a new valid reference.

Chris17
Tera Contributor

Hello, 

Thank you for the help. When I configured the onChange client script, nothing happens. Is it possible to clear a field when there is no default/null value?

find_real_file.png

You're welcome 🙂

Yes, you just have to move the || newValue == '' part from the 1st if into the other if.

Chris17
Tera Contributor

Hi there,

That didn't seem to work. Am I doing something wrong still? Apologies as I am new to scripting in general.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (g_form.getValue('user_location') == 'Remote/Virtual' || newValue == '') {
        g_form.clearValue('user_location_parent');
    }
}