how to add/remove option for reference field based on a field selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 03:18 AM
I have two fields "application"(with 3 values) and another reference field "code".
So based on selection of application (value), I want to control the reference field code to add/remove the value none from the reference table.
I understand that addoption/removeoption only works on choice list.So is there any other way out for this?
This is urgent.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 03:54 AM
Hi Jasmine,
Then you can configure your reference field to show as a choice list with none.
And then based on onchange client script of application, you can remove other options if application matches your app.
for others, leave as is.
Mark the comment as a correct answer and also helpful once worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2019 03:52 AM
Hi Jasmine,
Refer this example, i have two fields location and building, if select a value as Pune in location then only buildings in Pune location should be displayed in building field.
Write a script include make it client callable
Script include:
function buildingdropdown()
{
var gp = ' ';
var tp=current.variables.location;
var u=new GlideRecord('cmn_building');
u.addQuery('location',tp);
u.query();
while(u.next())
{
//gs.addInfoMessage(tp);
gp += (',' + u.sys_id);
}
return 'sys_idIN' + gp;
}
Client script: type-onChange, Variable name- select on which you want to change
var ga = new GlideAjax('scriptinclude_name');
ga.addParam('sysparm_name','function_name in script include');
ga.getXML(dropdown);
function dropdown(response)
var answer = response.responseXML.documentElement.getAttribute("answer");
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy.
Thanks,
Ruhi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2021 05:10 AM
Hi all it's worked form me using :
g_form.removeOption("fildname","choice_sys_id");
exmple:
my fieldname : type;
i have a choice called "abc" i need to remove it from the choice list so i copy the "abc" sys id from the reference table record .
g_form.removeOption("type","3bcdccf9db26d740afa29532ca9619**");