on select of group all user from same group is not map on list collector field

rmaroti
Tera Contributor

On reference type of field when group is selected then that group member should be map on list collector field it is map but only one user map not map other user what will be the issue?.

 

Script Include:

var checkGroupMember = Class.create();
checkGroupMember.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkMember: function() {
var arr =[];
var member = this.getParameter('sysparm_member');
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', member);
gr.query();
while (gr.next()) {
arr.push(gr.user);
}
return arr.toString();
},
type: 'checkGroupMember'
});

 

 

 

 

 

client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

// var abc = g_form.getValue('group');
var gr = new GlideAjax('global.checkGroupMember');
gr.addParam('sysparm_name', 'checkMember');
gr.addParam('sysparm_member', newValue);
gr.getXMLAnswer(pop);

function pop(response) {
var answer = response.split(",");
alert(answer);

g_form.clearValue('user_add');
g_form.setValue('user_add', answer);

7 REPLIES 7

Maik Skoddow
Tera Patron
Tera Patron

???

Brad Bowman
Kilo Patron
Kilo Patron

If you were to add some informational logs to the Script Include, you would see that the same sys_id is repeatedly pushed into the array.  This is due to the field type of sys_id looking like a string, but it isn't, so when pushed to an array the memory location is what is pushed, not the set of characters you are expecting.  Force the field to a string value to correct this:

arr.push(gr.user.toString());

In the Client Script response function, you don't need/want to split the answer, since a List Collector type variable / List type field stores a comma-separated string of sys_ids, so that's what you use to set the value also.  In your case you are splitting it into an array, then not doing anything with the array, but setting the value to the (implied) join of the array, so just use:

function pop(response) {
    alert(response);
    g_form.clearValue('user_add');
    g_form.setValue('user_add', response);
}

 

still using your solution I'm not getting group value I can see only  sys id on select of group in the description.

 

Please find attached document

That's what I would expect when not using toString or getValue.  Post your updated scripts, and add a infoMessage / log to the SI to confirm this is the function/SI that is executing.  This may not matter, but you should also join the array instead of using toString on the return:

gs.addInfoMessage('SI running ' + arr.join(','));
return arr.join(',');