Using Dependent Fields in Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 09:32 AM
I am having issues trying to get a Dependent field relationship to work in the Service Portal.
There is a field in alm_asset table named “Substatus” that is dependent on a field named “State” in the alm_hardware table. All the possible entries for both fields can be found in the “sys_choice” table.
So, I have created a Reference field named “Desired State” in my Service Portal form. Upon selection of that field, the options for the Multiple Choice field on my form named “Desired Substatus” should be filtered by the following values (in the “sys_choice” table):
- Table name is “alm_asset”
- Element is “Substatus”
- Inactive is false
- Dependent value should match the value from the “Desired State” selection
I have trying to mess around with a Catalog Client Script, like the one shown here: https://community.servicenow.com/community?id=community_question&sys_id=7db05f69dbdcdbc01dcaf3231f96..., but have not had any success.
Can someone help me to get this to work?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 03:25 PM
Is Desired Substatus also a reference field? Is yes, you just need a reference qualifier to filter the choices based on Desired State. Something like: javascript:"Desired State =" + current.variables.u_desired_state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2018 04:46 AM
[quote]Is Desired Substatus also a reference field[/quote]
It can be. I am trying to determine if it is better to set it up as a Reference field or as Multiple Choice field. I am just trying to find one that works.
[quote]Is yes, you just need a reference qualifier to filter the choices based on Desired State. Something like: javascript:"Desired State =" + current.variables.u_desired_state[/quote]
No, unfortunately it does not work. Remember, all these choices are listed in the sys_choice table. The relationship between the two is that the "Dependent value" field in the "Desired Substatus" records in the at table needs to match the "Value" field in the "Desired State" records in the same table.
Unfortunately, "current.variables.desired_state" returns the sys_id for the record, when I actually need to return the "Value" field from that record. I am not sure how to accomplish that.
From all my research in past questions, it appears that it cannot be done with a Reference Qualifier, and will require some scripting (either a Catalog Client Script, a Script Includes, or both). I just cannot get it to work out.
EDIT: How do you do "quotes" on this board? I see how to insert code, but not quotes. There does not seem to be an icon for that. I thought there used to be...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2018 07:58 AM
OK. I was able to get this to work out by coming at it from a different angle, using the methodology described here: https://community.servicenow.com/community?id=community_question&sys_id=9561d72ddbdcdbc01dcaf3231f96....
This uses a Script Includes function in the Reference Qualifier of the "Desired Substate" Reference field on the Catalog Item.
Here is what the Script Includes code looks like:
function getSubstates(){
var subStList = ' ';
var i = 0;
var st = current.variables.desired_state.value;
var gr = new GlideRecord('sys_choice');
gr.addQuery('name','alm_asset');
gr.addQuery('element','substatus');
gr.addQuery('inactive',false);
gr.addQuery('dependent_value',st);
gr.query();
while(gr.next()) {
if (subStList.length > 0) {
//build a comma separated string of groups if there is more than one
subStList += (',' + gr.sys_id);
i += 1;
}
else {
subStList = gr.sys_id;
}
}
// return a list of sus_user id's for the selected company
return 'sys_idIN' + subStList;
}