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,



Please find the modified code below. I believe this should work for the List collector type variable also.


      var answer= '';


      var grp= current.variables.variable_name;  


      var gr   = new GlideRecord('sys_user_grmember');


      gr.addQuery('group', grp);  


      gr.query();


    while(gr.next()) {


              if (answer.length > 0) {                      


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


              }


              else {


                      answer= gr.user.sys_id.toString();


              }


      }


      return 'sys_idIN' + answer;



Find the snapshot below:


find_real_file.png



I hope this helps.Please mark correct/helpful based on impact


Hi Amlan,


I cant understand why this script include is not working. can you find anything wrong here? and javascript:findUser(); I have used in Affected User (list collector ) is it alright?



Script include 1.JPG


Hi Sreeja,



The code of Script Include which I have provided in my last response works perfectly fine for the 'Reference' type variable. I have cross checked in my personal instance. You need to call the script include in the advance reference qualifier as javascript:findUser();


However, in reference qualifier in List Collector type variable doesn't work correctly. You can refer Ankur's response in this thread Advanced reference qualifier on a variable in order guide .


For more information on using Reference qualifier in List Collector type variable you can also refer this blog: Filtering on the List Collector or SlushBucket variable in Helsinki .


As of now, if the requirement remains same, i.e., to show list of Users based on selected Group, I would suggest you to change the variable type from 'List Collector' to 'Reference'. However, I will get back to you later if I find any solution for List Collector type variables.



I hope this helps.Please mark correct/helpful based on impact


Thank you so much Amlan.


But its not possible for me to change the type of this variable since multiple user can be there. please get back to me if you find anything.


Thanks Again.



Regards,


Sreeja


Hi Sreeja,



I have debug your issue and found the issue more interesting. Hence initiated a new thread regarding the same. Please track this thread over here Reference Qualifier Issue in List Collector Type Variable and hope you will get your answer over there.


If you want, you can also mark corresponding answer correct, close this thread and track the thread mentioned in this response.



I hope this helps.Please mark correct/helpful based on impact