Trying to get the group names in Assignment group variable which requested for belongs to

raj99918
Tera Contributor

Hi ,

 

Get list of groups thats Requested for belongs to in a catalog form variable called Assignment group I have written script include and onChnage catalog client as below but some how it's not setting the values in the refernce variable  and also am able to get the sys_ids's of all the groups from script include but its not setting it in the reference variable

 

Note: This is in scoped application not in Global scope

 

 

Script include:

 

var GroupsMembership = Class.create();
GroupsMembership.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getGroups: function() {
        var groups = [];
        var user = this.getParameter('sysparm_userID');
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', user);
        gr.query();
        while (gr.next()) {
           groups.push(gr.group.sys_id);
        }
return 'sys_idIN' + groups;
    },

    type: 'GroupsMembership'
});
 ------------------------------------------
Onchange catalog client script:
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var gajax = new GlideAjax('GroupsMembership');
    gajax.addParam('sysparm_name','getGroups');
    gajax.addParam('sysparm_userID', newValue);
    gajax.getXML(getResults);
}
function getResults(response){
    var answer = response.responseXML.documentElement.getAttribute("answer");
var req = g_form.getValue('requested_for');
if(req !=''){
alert(answer);
   g_form.setValue('assignment_group', answer);
}
}
22 REPLIES 22

Sumanth16
Kilo Patron

Hi @Sumanth16 Thanks but still no luck

Vrushali  Kolte
Mega Sage

Hello @raj99918 ,

 

In the SI function while returning sys_id of groups, remove the string 'sys_IIN' and replce it with -

 

return groups.join(',');

 

 

Also, in the client script try setting the value of reference field like -

 

 

 var groupSysIds = answer.split(',');
 g_form.setValue('assignment_group', groupSysIds.join(','));

 

 

 

Let me know if it works,

 

If my answer solves your issue, please mark it as Accepted✔️ and Helpful 👍!

Hi @Vrushali Kolte  Thanks for the changes but still its not working it is showing all the group names instead of filter groups from requested user