Dynamic reference qualifier in list collector

sreejamukherjee
Kilo Expert

Hi All,

I have a requirement to automate

1)assign role to users

2)assign users to a requested group

3)remove role from users

4)remove users from group.

through a catalog item.I am done with the flow.But if remove user from the group is selected from a particular group then only the user need to be populated who is within that group only.for that I need a dynamic reference qualifier.

for that we have some fields

1)Affected Users(List collector)

2)Required Group(reference)

The requirement is like depending on the group the user will be populated in Affected Users field.

can anyone please help me with the script.

Regards

Sreeja

1 ACCEPTED SOLUTION

sreejamukherjee
Kilo Expert

Hi All,


Thanks for all of your responses.


Finally I got the resolution of my problem and here is the code that I have used in OnChange client script.


function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


  var grp = g_form.getValue('name_grp');


  var usr;


  var mem = 'group_mem';


  var rightBucket= gel(mem+'_select_1');


  var leftBucket = gel(mem+'_select_0');


  rightBucket.options.length = '0';


  var gr = new GlideRecord('sys_user_grmember');


  gr.addQuery('group',grp);


  gr.query();


  while(gr.next()){


  usr=gr.user;


  var selectedOptions = leftBucket.options;


  var selectedIDs = new Array();


  var index = 0;


  for(var i = 0; i < selectedOptions.length; i++){


  //alert(selectedOptions[i].value);


  if(selectedOptions[i].value == usr){


  //alert('1nsideif');


  selectedIDs[index] = i;


  index++;


  }


  }


  moveSelectedOptions(selectedIDs, leftBucket, rightBucket, '--None--');


  }



Regards


Sreeja


View solution in original post

24 REPLIES 24

HI Sreeja,



I am aware of your requirement. But if no group is selected, Let me know what you want to show in Affected user list.


Hi Sneha,


If no group is selected then all the users should be available in the list since it refers to user table.Depending on the group user list needs to be modified.



Regards,


Sreeja


Sreeja,



Thats the reason i asked you need to add a check in your script include if group name is empty, in that case you need to return all the user records.




oharel
Kilo Sage

Hi Sreeja,



I am not sure if this will help you, but you can have an onChange client script, instead of using a script include and reference qualifier.


Field one: group - your reference field to the group table


Field two: affetced user list - your list reference to sys_user table


onChange running on field group:


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading) {


  return;


  }



  //Type appropriate comment here, and begin script below


  var grp = g_form.getValue('u_group');\\this is your group field


  if(newValue=='') {


  g_form.clearValue('u_affected_user'); \\this is your affected user field


  }


  var group = new GlideRecord('sys_user_grmember');


  group.addQuery('group', grp);


  group.query();


  while(group.next()) {


  var list = group.user;


  var array = list.split(',');


  for(var i=0; i<array.length;i++) {


  var p = new GlideRecord('sys_user');


  p.addQuery('sys_id', array[i]);


  p.query();


  p.query(getMeTheNames);


  }


  }


}



function getMeTheNames(p) {


  var list = new Array();


  while (p.next()) {


  list.push(p.sys_id);


  }


  g_form.setValue('u_affected_user', list);


}



harel


Please mark as correct or helpful based on impact


Hi Harel,


Thanks foe your response but it did not work..



Regards,


Sreeja