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.

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

Hello @raj99918 ,

 

Instead of using a client script you can make use of reference qualifier on assignment_group variable as follows -

 

javascript: new GroupsMembership().getGroups();

VrushaliKolte_0-1721757037180.png

Keeping the return statement as is return 'sys_idIN' + groups;

 

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

 

Hi @Vrushali Kolte ,

 

Am developing this is on scoped application still the reference qualifier is same or need to modify anything If yes please let me know 

If its a scoped application just try to add the API name of SI.

VrushaliKolte_0-1721757959810.png

 

e.g. javascript: new API_name_SI().function_name();\

 

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

 

Hi @Vrushali Kolte   javascript:new x_rc_er_li.GroupsMembership().getGroups();

 

I have written as suggested by you but still no luck in getGroups function Do I need to add (current.variables.requested_for)?

Hi @raj99918 ,

 

Please provide the reference qualifier which you added in the field?

 

Thanks & Regards,
Sumanth Meda