Advanced reference qualifier call to script include not working

R9
Tera Contributor

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- 

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 = current.assigned_to;
        var userID= assigned_to;
        gs.info("Script include" + userID);
        var usergroups = [];
        alert("InteractionAssignmentGroup");
        gs.log('[DEBUG] InteractionAssignmentGroup');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery("user", gs.getUserID());
        gr.addQuery("group.active", true);
        // gr.addEncodedQuery('user.user_name=' + userID + '' );
        gr.query();
        while (gr.next()) {
            usergroups.push(gr.getValue('group'));
        }
        gs.log('[DEBUG] Groups for User ID: ' + userId + '\n' + usergroups);
       
        return usergroups;
    },
    type: 'InteractionAssignmentGroup'
});
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@R9 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

VarunS
Kilo Sage

@R9 

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
    });
}