- 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-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 08:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 08:09 AM
You're welcome 🙂
Yes, you just have to move the || newValue == ''
part from the 1st if into the other if.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 09:43 AM
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');
}
}