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

That looks OK. Assuming 'Remote/Virtual' is really the value in user_location and not just the label.

Because the onChange script is for field user_location, you don't need to use g_form.getValue('user_location'), newValue will contain exactly that, so you can just write

if (newValue == 'Remote/Virtual' || newValue == '') {

Next I would try to set the value to empty string, in place of using clearValue:

g_form.setValue('user_location_parent', '');

Also

- could you post text/script, not picture, so I could just modify it?

- I can see that UI Type == 'Desktop'; this will make the client script only be executed when the Catalog Item is opened in CMS. If you want to make this also work in Portal, you have to change UI Type to All (or at least Mobile / Service Portal)

Allen Andreas
Administrator
Administrator

Hi,

I believe you may be confused as the "removeOption" method is for select-box field where you're trying to remove a choice.

If you're trying to apply a reference qualifier, then you'd want to set that on the reference field itself, so not in Client Script or UI Policy. And you'd use something like:

javascript:if (current.variables.field_name == 'value') { "reference qual here" };

So you'd want to replace field_name with the appropriate field name that you're evaluating if it equals a particular value. Then, in the reference qual here section, you'd input your actual reference qualifier (it's recommended to go to list view for these records and build the filter as you need to replicate the scenario, then right-click the last piece of the breadcrumb trail where your filter is applied and choose "copy query", and then paste it here).

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

PratyushaBodepu
Mega Guru

Hi Chris, 

Please find the below implementation of János's approach. I have implemented it in my PDI and I am able to filter the values in Reference field.

Here, I am filtering the values appearing in the 'Current Location' field which is a reference to cmn_location table. When User Location is selected as 'Virtual', the current location filters out New York.

find_real_file.png

find_real_file.png

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!