Reference Qualifiers
Reference Qualifiers
Reference Qualifiers
Overview
Use reference qualifiers to restrict the data that is selectable for a reference field. For example, if you want records
with the San Diego location name to be referenced by another record, you can create a reference qualifier on the
Location field of the record. The qualifier specifies that the user can choose only location records with the City field
set to San Diego for the Location field.
3.
4.
5.
6.
The Dictionary Entry form opens. The simple reference qualifier is available on both the Default view and the
Advanced view. The dynamic and advanced reference qualifiers are available only in the Advanced view.
To change views, select Default view or Advanced view under Related Links.
In the Reference Specification section, verify that the table already present in the Reference field is the correct
one, or select another table if necessary.
Select the type of qualifier in the Use reference qualifier choice list.
Configure the qualifier:
Reference Qualifiers
Reference cascade rule: allows you to define what happens to a record if the record it references is deleted.
Reference floats: enables the Edit button on related lists for one-to-many relationships
Dynamic creation: lets you determine if the system should create a new record when a value for the reference
field does not match an existing record. If you select this option, enter a script in the Dynamic creation script
field that specifies how to create the record.
8. Click Update.
Dynamic Reference
Qualifier Example
Advanced Reference
Qualifier Example
Use advanced reference qualifiers if
you want to enter an encoded query
string or make a JavaScript call to a
script include that returns a query
A dynamic reference qualifier
Reference Qualifiers
string. To create advanced reference qualifiers, enter the query string or JavaScript code in the Reference qual field
on the Dictionary Entry form.
Note: As a good practice, make JavaScript calls to functions in a script include instead of a global business rule. See Business Rules
Best Practices for more information.
JavaScript Calls
An example of a JavaScript call is the
following code:
javascript:new myScriptInclude().my_refqual()
This code calls a function named my_refqual() in a script include named myScriptInclude(). The
function must return a query string that can filter the options available on a reference field.
JavaScript Example: Limiting the Assigned to Field by Users with a Specified Role
This example shows how to restrict an incident's Assigned to choices to only the users with the itil_admin role. You
could also change itil_admin to any other role on a refernece field that refers to the User table.
1.
2.
3.
4.
5.
Open an incident.
Right-click the Assigned to field and select Personalize Dictionary.
In the Reference qual field, enter javascript:"sys_idIN"+getRoledUsers("itil_admin").join(",").
Save the record.
To see the base-system business rule that this JavaScript code calls, navigate to System Definitions > Business
rules.
6. Open getRoledUsers.
7. The business rule uses the following JavaScript code:
// Return an array of sys_ids of the users that have at least one role
// optional parameters allow the exclusion (NOT IN) of some roles or
// look for specific roles (IN)
//
// optional: queryCondition - 'IN' or 'NOT IN'
// optional: roleList - a comma separated list of role names
//
function getRoledUsers(queryCondition, roleList) {
var roleListIds;
Reference Qualifiers
if (queryCondition && roleList) {
roleListIds = getRoleListIds(roleList);
}
var users = {};
var gr = new GlideRecord('sys_user_has_role');
if (roleListIds) {
gr.addQuery('role', queryCondition, roleListIds);
}
gr.query();
while (gr.next()) {
users[gr.user.toString()] = true;
}
var ids = [];
for (var id in users)
ids.push(id);
return ids;
}
// get sys_id's for the named roles
function getRoleListIds(roleList) {
var ids = [];
var gr = new GlideRecord('sys_user_role');
gr.addQuery('name','IN',roleList);
gr.query();
while (gr.next()) {
ids.push(gr.sys_id.toString());
}
return ids;
}
JavaScript Example: Constraining the Assignment Group Field
This example shows how to restrict an incident's Assignment group choices to only the groups that contain the user
already specified in the Assigned to field.
1.
2.
3.
4.
5.
6.
7.
Open an incident.
Right-click the Assignment group field and select Personalize Dictionary.
Enter javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup() in the Reference qual field.
Save the record.
Navigate to System Definitions > Script Includes.
Click New.
Create a script include with the following JavaScript code:
Reference Qualifiers
BackfillAssignmentGroup:function() {
var gp = ' ';
var a = current.assigned_to;
//return everything if the assigned_to value is empty
if(!a)
return;
//sys_user_grmember has the user to group relationship
var grp = new GlideRecord('sys_user_grmember');
grp.addQuery('user',a);
grp.query();
while(grp.next()) {
if (gp.length > 0) {
//build a comma separated string of groups if
there is more than one
gp += (',' + grp.group);
}
else {
gp = grp.group;
}
}
// return Groups where assigned to is in those groups we
use IN for lists
return 'sys_idIN' + gp;
},
type: 'BackfillAssignmentGroup'
}
The next time you create an incident, select a user in the Assigned to field. Then click the Assignment group
lookup icon. Only the groups that contain the user you just selected appear. For example, if Bob Smith belongs to the
Database group and the Networking group and you assign an incident to Bob, the only options you can select for the
assignment group are Database and Networking.
Reference Qualifiers
cmdb_rel_ci_child_refQual:function()
6
{
if (listEditRefQualTag == "application")
return "sys_class_name = cmdb_ci_appl";
if (listEditRefQualTag == "database")
return "sys_class_name = cmdb_ci_database"
}
Troubleshooting
If you receive a Bad Gateway Error in Internet Explorer when searching in a reference lookup window, then you
cannot use ref_qual_elements=* in the advanced reference qualifier.
Enhancements
Eureka
Administrators can create reference qualifiers using a simple condition builder, dynamic filtering options, or an
advanced query or script.