Catalog Client Script Issue

Chris Doernbra1
Mega Guru
//Get the sys_id of the group and pass it into the glideajax
 
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var group = g_form.getValue('group');
var ga = new GlideAjax('GetGroupMembers');
ga.addParam('sysparm_name', 'getMembers');
ga.addParam('sysparm_groupSysId', group);
ga.getXML(setUsers);

 

function setUsers(response) {

 

var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('current_members', answer);
}

 

}
 
//Script Include
 
var GetGroupMembers = Class.create();
GetGroupMembers.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getMembers: function(groupSysId) {
gs.info('XX: START - Group ID: ' + groupSysId);

var userSysIds = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();

while (gr.next()) {
var userId = gr.getValue('user'); // Correctly retrieve sys_id
gs.info('XX: Found User Sys ID - ' + userId);
userSysIds.push(userId);
}

var result = userSysIds.length ? userSysIds.join(',') : "No Members Found";
gs.info('XX: Final User List - ' + result);

return result;
},

isPublic: function() {
return true; // Allows public access
},
});
 
When I run this from the catalog item and select a group, the expectation is that the script include will look up all the members and then set the list collector. What I am seeing is that the group sys_id is not making it into the script include. The log prints XX: START - Group ID: undefined. I have validated that the group sys_id is getting pulled from the catalog item by putting in an alert into the catalog script, alert(g_form.getValue('group'));
 
What am I missing here? I have turned off the ACLs and also added isPublic. I also hard coded a sys_id into the catalog client script and it still returns no members. This sort of tells me that the sys_id isn't making into the script include but I am not sure why.
3 REPLIES 3

anshul_goyal
Kilo Sage

Hi @Chris Doernbra1,

When calling a client-callable Script Include, you don’t need to pass or define an argument-based function. In your code, you're doing exactly that, which is why you're not receiving the group sys_id and its corresponding members in the result variable. To fix this, you can add the following line to your code:

var groupSysId = this.getParameter('sysparm_groupSysId');

 
Also, please remove the argument in your function and try it again.

Please mark my solution as helpful and accepted for future reference.

Thanks

Bhavya11
Kilo Patron

Hi @Chris Doernbra1 ,

 

Please change logic in Script include 

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

getMembers: function() {
var groupSysId = this.getParameter('sysparm_groupSysId');
gs.info('XX: START - Group ID: ' + groupSysId);

var userSysIds = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', groupSysId);
gr.query();

while (gr.next()) {
var userId = gr.getValue('user'); // Correctly retrieve sys_id
gs.info('XX: Found User Sys ID - ' + userId);
userSysIds.push(userId);
}

var result = userSysIds.length ? userSysIds.join(',') : "No Members Found";
gs.info('XX: Final User List - ' + result);

return result;
},

isPublic: function() {
return true; // Allows public access
},
});

 

 

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,

BK

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Chris Doernbra1 

you are not accepting the parameter you are passing from GlideAjax

update script as suggested by other members and share the status

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader