servicenow advanced reference qualifier call by script include

salaheddinezaf1
Tera Contributor

i want to call my script include into the advanced reference qualifier and this my script include 

var groupManager = Class.create();
groupManager.prototype = {
    initialize: function() {
    },
    findITILManager:function(){
        try{
            var users=[];
            var gr = new GlideRecord("sys_user_has_role");
            gr.addEncodedQuery('role.name=itil');
            gr.query();
            while (gr.next()) {
            users.push(gr.user.sys_id);
            }
            return users.toString();
        }catch(error){
            gs.error(error);
        }
       
    },

    type: 'groupManager'
};
 
-------------> for the call into the i use this   =  
Reference Qual
javascript:new groupManager().findITILManager()

in the background script it work but when i use the search icon it give all the users 

2 ACCEPTED SOLUTIONS

Zach Koch
Giga Sage
Giga Sage

You need to return a query string. Currently you are only returning an array of user sys ids. Your code would look like this, changing your return value

 

var groupManager = Class.create();
groupManager.prototype = {
    initialize: function() {
    },
    findITILManager:function(){
        try{
            var users=[];
            var gr = new GlideRecord("sys_user_has_role");
            gr.addEncodedQuery('role.name=itil');
            gr.query();
            while (gr.next()) {
            users.push(gr.user.sys_id);
            }
            return 'sys_idIN' + users.join(',');
        }catch(error){
            gs.error(error);
        }
       
    },

    type: 'groupManager'
};

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

View solution in original post

Sandeep Rajput
Tera Patron
Tera Patron

@salaheddinezaf1 Here is the script you should try.

 

var groupManager = Class.create();
groupManager.prototype = {
    initialize: function() {
    },
    findITILManager:function(){
        try{
            var users=[];
            var gr = new GlideRecord("sys_user_has_role");
            gr.addEncodedQuery('role.name=itil');
            gr.query();
            while (gr.next()) {
            users.push(gr.getValue('user'));
            }
            return 'sys_idIN'+users.toString();
        }catch(error){
            gs.error(error);
        }
       
    },

    type: 'groupManager'
};

Hope this helps.

View solution in original post

2 REPLIES 2

Zach Koch
Giga Sage
Giga Sage

You need to return a query string. Currently you are only returning an array of user sys ids. Your code would look like this, changing your return value

 

var groupManager = Class.create();
groupManager.prototype = {
    initialize: function() {
    },
    findITILManager:function(){
        try{
            var users=[];
            var gr = new GlideRecord("sys_user_has_role");
            gr.addEncodedQuery('role.name=itil');
            gr.query();
            while (gr.next()) {
            users.push(gr.user.sys_id);
            }
            return 'sys_idIN' + users.join(',');
        }catch(error){
            gs.error(error);
        }
       
    },

    type: 'groupManager'
};

 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

Sandeep Rajput
Tera Patron
Tera Patron

@salaheddinezaf1 Here is the script you should try.

 

var groupManager = Class.create();
groupManager.prototype = {
    initialize: function() {
    },
    findITILManager:function(){
        try{
            var users=[];
            var gr = new GlideRecord("sys_user_has_role");
            gr.addEncodedQuery('role.name=itil');
            gr.query();
            while (gr.next()) {
            users.push(gr.getValue('user'));
            }
            return 'sys_idIN'+users.toString();
        }catch(error){
            gs.error(error);
        }
       
    },

    type: 'groupManager'
};

Hope this helps.