- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:57 AM
Hello,
I am trying to use an advanced reference qualifier to call a script include for filtering the assignment group. But my script include does not seem to be getting hit. I placed alerts and gs.info statement but they do not seem to be getting hit. What am I doing wrong?
Reference qualifier: javascript: new InteractionAssignmentGroup().getUserGroups(current.assigned_to);
Script include-
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 09:48 AM
I assume both the field, script include are in same scope
try this
var InteractionAssignmentGroup = Class.create();
InteractionAssignmentGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
//Get list of all assignment groups that the user is part of
getUserGroups: function(assigned_to) {
var userID = assigned_to;
var usergroups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("user", userID);
gr.addQuery("group.active", true);
gr.query();
while (gr.next()) {
usergroups.push(gr.getValue('group'));
}
return 'sys_idIN' + usergroups;
},
type: 'InteractionAssignmentGroup'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:45 AM
Try the below script include and make it client callable.
var InteractionAssignmentGroup = Class.create();
InteractionAssignmentGroup.prototype = Object.extendsObject(GlideAjax, {
// Get list of all assignment groups that the user is part of
getUserGroups: function() {
var userID = this.getParameter('sys_id'); // Get the user ID passed from the client script
gs.info("Script include hit with userID: " + userID);
var usergroups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery("user", userID);
gr.addQuery("group.active", true);
gr.query();
while (gr.next()) {
usergroups.push(gr.getValue('group'));
}
gs.info('[DEBUG] Groups for User ID: ' + userID + '\n' + usergroups.join(', '));
return usergroups.join(',');
},
type: 'InteractionAssignmentGroup'
});
Use the below reference qualifier
javascript: new InteractionAssignmentGroup().getUserGroups();
use the below Client to call the script include and pass the assigned_to parameter:
function onLoad() {
var ga = new GlideAjax('InteractionAssignmentGroup');
ga.addParam('sys_id', g_form.getValue('assigned_to'));
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assignment_group', answer); // Set the assignment group field with the filtered results
});
}