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

amlanpal
Kilo Sage

Hi Sreeja,



You need to refer the variable to User Role (sys_user) table. And in the Script include you need to return the sys_id's of the user who belongs to the same group.


The Sample code of the Script include will be something like below (please note it is untested). Let me know if you find any issue with the code. Also call the script include in your Advance reference qualifier as: javascript:findUser();



function findUser(){  


  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).toString();    


  }


  else{


  answer= gr.user.toString();


  }


}


    return 'userIN' + answer;


}



I also have answered similar question earlier. You may refer the below threads:


1. Service catalog lookup Select Box choice's validation based on a table fields.


2. Script Include Advanced Reference Qualifier help required



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


Thanks Amlan for your help but the script is showing an error at line "answer+ = (',' + gr.user).toString(); " and also can you please tell me why did you use "userIN" in return.


I think I need to clarify that the Group field is reference and the Affected Users field is List collector type field.So is there any problem since its list collector?



Regards,


Sreeja


Hi Sreeja,


Try changing it to "answer+ = (',' + gr.user.toString());



Hope this resolves your error.



Thanks Sneha for your help. I tried with your process but it did not work.


My Requirement is if I select any group the members of that group should be available in user list.


For that I have a catalog item having fields


1)Group(reference)


2)Affected User(List Collector)


If I select any Group from this group field suppose "XYZ" the members of that group(example: a,b,c) needs to available in "Affected User" field.



Can anyone please help me on this?


Regards,


Sreeja