- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 06:23 PM
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.
The option im trying to remove still appears, see below:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 06:47 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 03:33 PM
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', '');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 08:42 AM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 06:48 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 09:59 PM
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.
Please mark reply as Helpful/Correct, if applicable. Thanks!