It seems there might be some remaining issues. Let's simplify it further and use standard ServiceNow functionalities to achieve the goal. Here, I will guide you through a simpler process, focusing on creating a report that dynamically checks assignment groups for a user using a filter.
Option: Create a Dynamic Report for User Assignment Groups
-
Navigate to Reports:
- Go to "Reports" > "Create New".
-
Define the Report:
- Name:
User Assignment Groups
- Source type:
Table
- Table:
sys_user_grmember
-
Configure Filters:
- Add a filter for
User:
- Field:
User
- Operator:
is
- Value: (leave empty for now)
-
Configure Columns:
- Add columns that you want to display, such as:
-
Save the Report:
- Save the report so it can be accessed later.
Using the Report with a User Filter
-
Run the Report:
- Navigate to your saved report "User Assignment Groups."
- Use the filter to enter the specific user for whom you want to see assignment groups.
-
Set as Interactive Filter:
- If you want to make the report more user-friendly, configure the report to allow for an interactive filter where the person running the report can specify the user:
- Go to the
Filter section.
- Add an interactive filter for the
User field.
Script for More Automated Implementation
Let's add a simple Script Include and a UI Action to ensure the user groups for Assigned To are displayed directly in the incident form.
Step-by-Step Implementation
1. Script Include
-
Navigate to Script Includes:
- Go to "System Definition" > "Script Includes".
-
Create New Script Include:
- Name:
AssignmentGroupsFetcher
- API Name:
AssignmentGroupsFetcher
- Client Callable:
Yes
- Active:
Yes
var AssignmentGroupsFetcher = Class.create();
AssignmentGroupsFetcher.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserGroups: function() {
var userSysId = this.getParameter('sys_id');
var result = [];
if (userSysId) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userSysId);
gr.query();
while (gr.next()) {
result.push(gr.group.name.toString());
}
}
return result.join(', ');
},
type: 'AssignmentGroupsFetcher'
});
2. UI Action
-
Navigate to UI Actions:
- Go to "System UI" > "UI Actions".
-
Create New UI Action:
- Table:
incident
- Active:
Yes
- Name:
show_user_groups
- Label:
Show User Groups
- Client:
Yes
- List Context Menu:
No
- Form Context Menu:
Yes
- Form Button:
Yes
- Script:
function showUserGroups() {
var userSysId = g_form.getValue('assigned_to');
if (!userSysId) {
alert("Please select an 'Assigned to' user.");
return;
}
var ga = new GlideAjax('AssignmentGroupsFetcher');
ga.addParam('sys_id', userSysId);
ga.getXMLAnswer(function(response) {
alert("Assignment Groups: " + response);
});
}
-
Onclick Function:
- Onclick:
showUserGroups()
Testing the Implementation
- Open any incident form.
- Ensure there's a user selected in the
Assigned to field.
- Click the
Show User Groups button you created.
- You should see a popup displaying the assignment groups of the selected user.
Troubleshooting
- Empty User Field: Make sure the
Assigned to field has a value.
- Active Records: Ensure the Script Include and UI Action are marked as active.
- Console Errors: Check your browser’s console for any errors and rectify them.
By using this process, you should be able to dynamically find and display the assignment groups for any user assigned to an incident. If you still encounter issues, please provide any error messages or specific details of what isn't working, and I'll help you troubleshoot further.