Populate the list of group members in a list collector as per the group selected in a reference field above

AkashD
Kilo Expert

Hey folks,

I have a requirement for a catalog item where I need to populate the list of group members in the right bucket of the list collector as per the group selected in a reference field above.

The form looks like this as of now :

find_real_file.png

The first field is reference to "sys_user_group" while the list collector is showing the users with a simple reference qualifer which says "active=true^user_name!=empty".

What I'm basically trying to achieve is to edit the group members (add or remove) using this form; I know that could later be achieved via the workflow, but as of now I'm struggling with this. I've tried plenty of scripts available in the community, but none of them seem to be working for me. 

Any slight help would be really appreciated! Thanks in advance!

1 ACCEPTED SOLUTION

@Ankur Bawiskar,

The code which I'm trying is below :

Client Script :

group_members is the name of the list collector

find_real_file.png

 

Script Include :

find_real_file.png

 

Any slight help would be highly appreciated, thanks!

View solution in original post

15 REPLIES 15

Wow You have a keen eye for detail @Ankur Bawiskar ! Thank you so much !

I just fixed that, and upon putting an alert with answer, I'm getting the list of users of the selected group and their sysID seperated by a '|'. The users and sysID themselves are separated by a comma! Somewhat like -

user_name1,user_name2,user_name3|sysID1,sysID2,sysID3

In the code, I have used :

g_form.setValue('group_members',memValues,memNames);

This is the last step which is not working I guess. Do we have some alternative to this ? I hear this part of the code needs to be different in portal and legacy ?

Hi,

for portal you can directly set sys_ids as below

g_form.setValue('group_members', memValues);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

if you need solution working for both native and portal below link you can refer

https://community.servicenow.com/community?id=community_question&sys_id=9664078ddbabccd05ed4a851ca96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

neelam135
Tera Contributor

Hi Akash did it work...I am in the same step...listcollector is not autopopulating?

@AkashD 

Did you find solution to your query as I could see you marked answer as correct?

It looks like you marked your own response as the correct answer, which may be confusing to others that read this later.

Do you still require assistance on this?

If yes then please correct this line; it should work in portal

g_form.setValue('group_members', memValues);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader