on select of group all user from same group is not map on list collector field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 04:17 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 04:37 AM
???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 06:05 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-17-2023 07:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 05:01 AM
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(',');