A couple of weeks ago someone asked me for some clarification on how to create a drop-down box that has values that change depending on the selected value of another drop-down box.
For example, if we are on incident form, and select a category of Restaurants, we may want the subcategory select menu change to only show subcategories of the Restaurant category, rather than all subcategories available to the form.
Rather than type out instructions or refer them to the wiki, it was quicker just to do a rough little video that showed how you might create drop-down list with values that are dependent upon the selection of another drop down choice list.
Sorry this is not polished, but it was a quick explanation of a simple process.
Hello John,
Its quite informative. I was wondering how this works if both the fields are of reference type.
For example, in the incident table, we have the fields ‘assignment_group’ and ‘assigned_to’. The assigned_to uses should populate depending on the assignment_group selected. Will it suffice just mentioning the ‘assignment_group’ as dependent field in the dictionary entry of ‘assigned_to’ field or there is something else at work.
Also, i tried to re-create the scenario with ‘role’ and ‘groups’ making groups dependent on role. But it didn’t work.
Will appreciate your suggestions. Also, i was wondering how the dependent field works? Whether it is referring to any relation table (such as sys_user_grmember in case of group and users) to populate the values in the dependent field.
Thank you
@Probir – hope this link helps you in your quest: http://wiki.servicenow.com/index.php?title=Reference_Qualifiers
Hello John,
Thanks for your response.
I created a global business rule and called it in reference qualifier of the ‘assigned_to’ field.
function getGroupUsers()
{
var grp = current.assignment_group;
var users = ”;
if(!grp)
return;
var grpUsers = new GlideRecord(‘sys_user_grmember’);
grpUsers.addQuery(‘group’,grp);
grpUsers.query();
while(grpUsers.next())
{
if(users.length > 0)
{
users = ‘,’ + grpUsers.user;
}
else
{
users = grpUsers.user;
}
}
return ‘sys_idIN’ + users;
}
The users are now populated based on the assignment_group selected.
However, when I remove the ‘assignment group’ entry from the dependent field of ‘assigned_to’,
it ceases to work.
I am not sure of the role the dependent field is playing here.
Would be very helpful if you shed some light.
Thank you,
Probir
Your code worked for me if I made these two changes:
if(users.length > 0)
{
//I ADDED A += RATHER THAN = TO THE USER LIST
users += ‘,’ + grpUsers.user;
}
else
{
//I ADDED A += RATHER THAN = TO THE USER LIST
users += grpUsers.user;
}
Thank you John for pointing out the mistake…
So I take it from here that the dependent field has no role to play in here.
Thank you! This helped me resolve my issue.
very nice
why below script not working for me
var my = Class.create();
my.prototype = {
initialize: function() {
},
return_user: function () {
var gr = new GlideRecord(‘sys_user_grmember’) ;
gr.addQuery(‘group’,’current.assignment_group’);
gr.query();
var users = ”;
while(gr.next()) {
users += ‘,’ + gr.user;
}
return ‘sys_idIN’+users;
},
type: ‘my’
};