Display only selected group users

AnilM99
Tera Expert

Hi Team,

 

I have two fields in incident table,

Service Group
Service User
These two fields should work same like Assignment group and assigned to.
I tried 'Reference qual' to call script include but it's not working
 
Reference qual: javascript: new getUserMembers.getMembers(current.u_service_group);
 
Server side Script include: 
var getUserMembers = Class.create();
getUserMembers.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

   
    getMembers : function(groupId){
        var id = [];
    var gr = new GlideRecord('u_service_user_grmember');
        gr.addQuery("u_service_group",groupId);
        gr.query;
        while(gr.next()){
            id.push(gr.getValue("u_user"));
        }
       
        return "sys_idIN"+id.toString();
    },
    type: 'getUserMembers'
});
 
Thank you
Anil!
 
4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

I assume you are populating Service Group before displaying the list of Service Users.  With your custom table you'll have to add some logs to see why it isn't working.  Put one at the beginning of the function to confirm it is running, and the value of groupId passed in from the form.  Add another inside the while loop so you can see if any records are returned.  Is your custom table available to all application scopes?

Eshwar Reddy
Kilo Sage

Hi @AnilM99 

I noticed a small correction needed in your code. The line should be gr.query().

Here’s the full corrected code:


getMembers: function(groupId) {
var id = [];
var gr = new GlideRecord('u_service_user_grmember');
gr.addQuery("u_service_group", groupId);
gr.query(); // Correctly call query method

while (gr.next()) {
id.push(gr.getValue("u_user"));
}

return "sys_idIN" + id.join(',');
},

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution


Thanks
Esh

protege747
Tera Contributor

image.png

 

* You should call the Script Include as it is in the API Name: "new x_something.getUserMembers().getMembers(current.u_service_group)."

 

* you should call the query method properly: "gr.query(); 


* Also, check if the Script Include is accessible from the specified scope

Moin Kazi
Kilo Sage
Kilo Sage

Hi @AnilM99 ,

 

Please check your reference qualifier to see how you’re calling it (the round brackets are missing when writing the ScriptInclude Name under the reference qualifier field).

 

You should write it in the following way:

 

Reference qual: javascript: new getUserMembers().getMembers(current.u_service_group);

 

And please write your script include function like that -

getMembers: function(groupId) {
var id = [];
var gr = new GlideRecord('u_service_user_grmember');
gr.addQuery("u_service_group", groupId);
gr.query(); 

while (gr.next()) {
id.push(gr.getValue("u_user"));
}
return "sys_idIN" + id.join(',');
},

 

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~