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

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

I tried this and now the script include gets hit, the first gs.info message can be seen in the log but it does not go inside the while 

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) {
        gs.info('inside script include');
        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()) {
            gs.info("inside while");
            usergroups.push(gr.getValue('group'));
        }      
        return 'sys_idIN' + usergroups;
    },
    type: 'InteractionAssignmentGroup'
});

It works, thank you!

I updated reference qualifier to this - 

javascript: new InteractionAssignmentGroup().getUserGroups(gs.getUserID()) ;

 

and script include to 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) {
        gs.info('inside script include');
        var userID = assigned_to;
        gs.info('inside 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'));
        }      
        return 'sys_idIN' + usergroups;
    },
    type: 'InteractionAssignmentGroup'
});

Bert_c1
Kilo Patron

I tested and see the gs.info() in Script log statements. The 'alerts' don't work in server scripts. use all gs.info() and look in the Script log statements module.