Reference Qualifier - User Story 02:
Title: Automatic Population of Initiator Group Field Based on Requester's Membership.
Details:
Automatic Population: If the requester is a member of only one group, the Initiator Group field should be auto-populated with that group's name.
Selection Options: If the requester is a member of multiple groups, the Initiator Group field should display those groups as selectable options.
Development Plan:
Create Script Include to filter and get requester groups.
Call Script Include in Advanced Reference Qualifier in Initiator group field Reference Specification section.
Development Steps:
Create Script Include:
Steps:
Navigate to All ==> System Definition ==> Script Includes
Click New (To create new Script Include). And give the below details in Script Include form.
Name : IT_Initiator_Group
Active : True
Script : (Add below script in script field (NOT Replace). Refer the below screenshots for more Information.)
(Note: This script include is not client callable.)
// Function: getGroups
// Description: Retrieves the groups associated with the specified requester.
// Parameters:
// - requester_SysID: The unique identifier of the requester.
// Returns:
// - A string containing a comma-separated list of groups that the requester user belongs to.
getGroups: function(requester_SysID) {
// Create a GlideRecord object to query the 'sys_user_grmember' table, which stores group membership information for users.
var gr = new GlideRecord('sys_user_grmember');
// Add a query to filter records where the 'user' field matches the specified requester_SysID.
gr.addQuery('user', requester_SysID);
// Execute the query.
gr.query();
// Initialize a variable to store the groups associated with the requester.
var requester_groups = '';
// Iterate over each record returned by the query.
while (gr.next()) {
// If it's the first group being added to the list, assign it directly to the requester_groups variable.
if (requester_groups == '') {
requester_groups = gr.group;
} else {
// If it's not the first group, append a comma and then the group name to the requester_groups string.
requester_groups = requester_groups + ',' + gr.group;
}
}
// Return the comma-separated list of groups associated with the requester user.
return requester_groups;
},
Click Save or Submit.
Now we have script include is ready. This script include needs to be called from Advance Reference Qualifier in Initiator Group field.
Call Script Include:
Steps:
Go to List view of Table: IT Support. (here, use your table).
Open any record.
Go and right click on Initiator group (Reference field) field label and select 'Configure Dictionary'.
Now, it opens Initiator group field dictionary page.
Go to Related Links and click on Advanced view.
Go to Reference Specification section, and give the below details.
Reference : Group
Use reference qualifier : Advanced
Reference qual :
javascript: new global.IT_Initiator_Group().getGroups(current.u_requester);
Note: Here,
global.IT_Initiator_Group => Script Include Class Name
getGroups => Function name in Script Include
u_requester => Reference field which refers to sys_user table and holds the requester name by default/onload.
Click Save or Submit.
Step by step Screenshots: