I want to show the group member in alert

AnkitT
Tera Contributor

Hello Community,

 

I want to show the group member in alert, can anyone tell me how to acheive this.

2 ACCEPTED SOLUTIONS

Abhishek_Thakur
Mega Sage

Hello @AnkitT ,

You can user the script include and glide Ajax to achieve this requirement.

 

// Script include

var Get_Group_Info = Class.create();
Get_Group_Info.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    demoTest:function(){
    var group = this.getParameter('sysparm_assignment_group');
    var GR = new GlideRecord("sys_user_group");
    GR.addQuery('sys_id',group);
    GR.query();
    if(GR.next()){
        var member = [];
        var mem1 = new GlideRecord("sys_user_grmember");
        mem1.addQuery('group',GR.getUniqueValue());
        mem1.query();
        while(mem1.next()){
            member.push(mem1.user.getDisplayValue().toString()); //This will return the members of that group
        }
        return member.toString();
    }
    },

    type: 'Get_Group_Info'
});
 
// Client script
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var ga = new GlideAjax('Get_Group_Info');
   ga.addParam('sysparm_name','demoTest');
   ga.addParam('sysparm_assignment_group',newValue);
   ga.getXMLAnswer(callback);
   function callback(response){
    var r = JSON.stringify(response);
    alert(r);
   }

 

View solution in original post

Abhishek_Thakur
Mega Sage

If you still need any help, you can connect with me.

View solution in original post

5 REPLIES 5

Abhishek_Thakur
Mega Sage

Hello @AnkitT ,

You can user the script include and glide Ajax to achieve this requirement.

 

// Script include

var Get_Group_Info = Class.create();
Get_Group_Info.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    demoTest:function(){
    var group = this.getParameter('sysparm_assignment_group');
    var GR = new GlideRecord("sys_user_group");
    GR.addQuery('sys_id',group);
    GR.query();
    if(GR.next()){
        var member = [];
        var mem1 = new GlideRecord("sys_user_grmember");
        mem1.addQuery('group',GR.getUniqueValue());
        mem1.query();
        while(mem1.next()){
            member.push(mem1.user.getDisplayValue().toString()); //This will return the members of that group
        }
        return member.toString();
    }
    },

    type: 'Get_Group_Info'
});
 
// Client script
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   var ga = new GlideAjax('Get_Group_Info');
   ga.addParam('sysparm_name','demoTest');
   ga.addParam('sysparm_assignment_group',newValue);
   ga.getXMLAnswer(callback);
   function callback(response){
    var r = JSON.stringify(response);
    alert(r);
   }

 

Abhishek_Thakur
Mega Sage

If you still need any help, you can connect with me.

Satishkumar B
Giga Sage
Giga Sage

Hi @AnkitT 

Script Include:

  • Retrieves the members of a group based on the provided sys_id.
  • Returns the list of members as a JSON-encoded string.

 

 

var Get_Group_Info = Class.create();
Get_Group_Info.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    demoTest: function() {
        var group = this.getParameter('sysparm_assignment_group');
        var member = [];
        
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', group);
        gr.query();
        
        while (gr.next()) {
            member.push(gr.user.getDisplayValue()); // Collect group member names
        }
        
        return JSON.stringify(member); // Return as JSON string for client-side handling
    },

    type: 'Get_Group_Info'
});
​

 

 

Client Script:

  • Sends the group sys_id to the Script Include.
  • Receives the list of members and displays it in an alert.

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    
    var ga = new GlideAjax('Get_Group_Info');
    ga.addParam('sysparm_name', 'demoTest');
    ga.addParam('sysparm_assignment_group', newValue);
    ga.getXMLAnswer(function(response) {
        var members = JSON.parse(response);
        alert("Group Members: " + members.join(', '));
    });
}
​

 

 

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

Prathamesh G
Kilo Sage
Kilo Sage

Hello @AnkitT , You can use the combination of the Client Script and Script Include to achieve your requirement. 

 

If the above solution helps to resolved your issue, Please mark the solution as Accepted solution and also mark it as Helpful.

 

Thank You.