How to populate group members in the dropdown?

varunp
Tera Guru

There is a dropdown in change page, where we need to populate all users listed in one particular group.

Any Idea how to do this?

8 REPLIES 8

Mike Allen
Mega Sage

Do an onLoad AJAX call that queries the group member table for that group, then use the addOption to add the members to the dropdown.



GlideForm (g form) - ServiceNow Wiki


This will get you started.   This queries the group you want the members from, then populates your field (I named it 'Test User Field') with the sys_ids of the group members. You can use this and figure out getting the display value (which is a dot-walk, and client scripts don't like dot-walk).


function onLoad() {


  //Type appropriate comment here, and begin script below


  var users = new GlideRecord('sys_user_grmember');


  users.addQuery('group', '287ee6fea9fe198100ada7950d0b1b73');


  users.query();



  while(users.next()){


  g_form.addOption('u_test_user_field', users.user, user.user);


  }


}


Hi Mike,



I wrote below script and still it is populating all users which is there in the servicenow.



function onLoad() {


    //Type appropriate comment here, and begin script below


  var users = new GlideRecord('sys_user_grmember');


  users.addQuery('group', '48b6c2d92b7671000b877fb5a8da15ae');


  users.query();




  while(users.next()){


  g_form.addOption('u_product_manager', users.user, users.user);


  }


 


}







SNOW.jpg


Oh, it looks like you want a reference qualifier on your reference field.   Hold on.