Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the member of assignment group?

AnkitT
Tera Contributor

Hello Community,

 

I want to get the member of assignment group in form of alert for incident form.

2 ACCEPTED SOLUTIONS

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @AnkitT ,

 

You can use the below code.

 

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());
        }
        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);
    alert(response);
    g_form.setValue("assigned_to",response);
   }


   //Type appropriate comment here, and begin script below
   
}

View solution in original post

Abhishek_Thakur
Mega Sage
Mega Sage

If still you need any help, you can DM me.

View solution in original post

3 REPLIES 3

Abhishek_Thakur
Mega Sage
Mega Sage

Hello @AnkitT ,

 

You can use the below code.

 

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());
        }
        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);
    alert(response);
    g_form.setValue("assigned_to",response);
   }


   //Type appropriate comment here, and begin script below
   
}

Abhishek_Thakur
Mega Sage
Mega Sage

If still you need any help, you can DM me.

Community Alums
Not applicable

Hi @AnkitT ,

I tried your problem in my PDI and it works for me please use below script

var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery("group.nameSTARTSWITHsoftware");
gr.query();
while(gr.next()){
	gs.print("Users = " + gr.user.getDisplayValue())
}

Result 

SarthakKashyap_0-1718277595757.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak