This example shows how to use an advanced reference qualifier with JavaScript and a
script include to restrict the incident Assignment group choices to
only the groups that contain the user specified in the Assigned to
field.
始める前に
Role required: personalize_dictionary or admin
手順
-
Open an incident.
-
Right-click the Assignment group label and select
Configure Dictionary.
-
If the form appears in Default view, under
Related Links, click Advanced
view.
-
In the Use reference qualifier field, ensure that the
Advanced option is selected.
-
In the Reference qual field, enter
javascript:new
ReferenceQualifierHelper().backfillAssignmentGroup().
-
Save the record.
-
Navigate to .
-
Click New.
-
Name your script includes as ReferenceQualifierHelper to match the Javascript in the following step.
This name ensures the API Name is generated correctly, based on the Name field.
-
Script includes with the following JavaScript code.
Ensure that the
Accessible form field is properly set for the environment.
var ReferenceQualifierHelper = Class.create();
ReferenceQualifierHelper.prototype = {
backfillAssignmentGroup:function() {
var assigneeGroupsQualifier = '';
var assignee = current.assigned_to;
//return if the assigned_to value is empty (this causes all groups to be returned)
if(!assignee)
return;
//sys_user_grmember has the user to group relationship
var grAssigneeGroups = new GlideRecord('sys_user_grmember');
grAssigneeGroups.addQuery('user',assignee);
grAssigneeGroups.query();
while(grAssigneeGroups.next()) {
if (assigneeGroupsQualifier.length == 0) {
// Create the beginning of the qualifier and add the 1st group
assigneeGroupsQualifier = 'sys_idIN' + grAssigneeGroups.getValue('group');
}
else {
// build a comma separated string of groups if there is more than one
assigneeGroupsQualifier += (',' + grAssigneeGroups.group);
}
}
// return Groups where assigned to is in those groups we use IN for lists
gs.log('DP: RefQual = ' + assigneeGroupsQualifier);
return assigneeGroupsQualifier;
},
type: 'ReferenceQualifierHelper'
};
次のタスク
To test, create an incident and select a user in the
Assigned to field. Click the Assignment
group lookup icon. Only the groups that contain the user you selected
appear. For example, you assign an incident to Bob Smith, who belongs to the
Database group and the Networking
group. The only options that appear in the assignment group are
Database and Networking.