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

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

 

View solution in original post

Sandeep Rajput
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

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

 

Sandeep Rajput
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.