I need to populate assigned to based on assignment group.

niveditakumari
Mega Sage

Hi, 

 

I need to populate assigned to based on assignment group. I have written this code and it is not working. 

niveditakumari_0-1707422000437.png 

niveditakumari_1-1707422097971.png

 

 

Please correct my code to make it work. 

 

Regards, 

Nivedita 

 

 

 

1 ACCEPTED SOLUTION

Rohini S Sane
Tera Guru

Hi @niveditakumari 

You can write below code in script include, its working on my PDI.

Script include code :

var populate_ag = Class.create();
populate_ag.prototype = {
    initialize: function() {
    },
myFunction : function(aggroup)
{
    var arr = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group',aggroup);
    gr.query();
    while(gr.next())
    {
arr.push(gr.user.toString());
    }
    return 'sys_idIN' + arr;
},
    type: 'populate_ag'
};
 
advanced ref qualifier script : javascript:new populate_ag().myFunction(current.u_group);
 
result.pngscriptinclude.pngadvref.png
 
Please mark helpful .
 
Thanks and Regards,
Rohini S Sane

View solution in original post

17 REPLIES 17

Mark Manders
Mega Patron

I dug up this one from a while back from my scripts. Can you try that? I think you're missing the 'join'. But on a different not: why set assignment group/assigned to from a catalog item? Isn't it better to just have the user create a ticket and use assignment rules to route that ticket to the correct group/user? You are letting users assign tickets. That's a process I wouldn't be happy with as an agent that needs to pick things up.

(function() {
    var groupId = current.variables.assignment_group; // Assuming 'assignment_group' is the variable name for the assignment group
    if (groupId) {
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('group', groupId);
        gr.query();
        if (gr.hasNext()) {
            // If the group has members, return only members of this group
            return 'sys_idIN' + getGroupMemberIDs(groupId);
        }
    }
    // If the group has no members or no group is selected, return all active users
    return 'active=true';
})();

function getGroupMemberIDs(groupId) {
    var memberIDs = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group', groupId);
    gr.query();
    while (gr.next()) {
        memberIDs.push(gr.user.toString());
    }
    return memberIDs.join(',');
}

 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

@niveditakumari, any luck with the script?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

swathisarang98
Giga Sage
Giga Sage

Hi @niveditakumari ,

 

If you want to show only users who are member of Assignment group in Assigned to Field then you can go to dictionary of "Assigned to" field and under Dependent Field Section you can give Assignment group backend name as shown below ,

swathisarang98_0-1707464104081.png

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,

Swathi Sarang

 

 

 

Rohini S Sane
Tera Guru

@niveditakumari 

Hello Nivedita ,

could you please try below script its's working on my instance.

 

var populate_ag = Class.create();
populate_ag.prototype = {
    initialize: function() {
    },
myFunction : function(aggroup)
{
    var arr = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group',aggroup);
    gr.query();
    while(gr.next())
    {
arr.push(gr.user.toString());
    }
    return 'sys_idIN' + arr;
},
    type: 'populate_ag'
};
 
advanced reference qualifier : javascript:new populate_ag().myFunction(current.u_group);
 
RohiniSSane_0-1707478354169.png

 

RohiniSSane_1-1707478354071.png

 

RohiniSSane_2-1707478354172.png

 

 
Thanks and Regards,
Rohini Sane

HI @Rohini S Sane

 

Thank you so much for your help. It is working now. 

I'm trying this code to populate assignment group based on assigned to field I have written code. 

niveditakumari_0-1707509700788.png

 

Can you please correct that to make it work. 

 

Regards, 

Nivedita