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

snehabinani26
Tera Guru

Hi Sreeja,



Try this code.


Create a script include and a function under it and write this code.




  var grp = current.variables.variable_name;   //Pass the variable name which selects Group


  var answer;


  var gr = new GlideRecord('sys_user_grmember');


  gr.addQuery('group', grp);


  gr.query();


    while(gr.next()){


    if (answer.length > 0) {


    answer+ = (',' + gr.user.getValue("sys_id"));  


  }


  else{


  answer= gr.user.toString();


  }


}


    return 'sys_idIN' + answer;




In the Reference qualifier of the Affected user list in advanced one call this script include with current object.




Hope this helps you.


snehabinani26
Tera Guru

Hi Sreeja


Try using --- javascript:new findUser().grMember();


Hi Sneha,


If I use this only four users are coming in Affected user field even before selecting the group name.


snehabinani26
Tera Guru

Hi Sreeja,



I assume you need to add a check if group name is empty, in that case you need to return all the user records.


Hi Sneha,


My requirement is if any group is selected the group members will be populated in Affected users field. But I don't know why this is not working.


If anyone have any solution please help.


Regards,


Sreeja