How can we show the members of the groups on the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 09:10 PM
Hi,
I have a requirement like to show all the members of the groups on a particular form. How we can Achieve this. Please help me if anyone have idea regarding this requirement and also share any documents you have.
Thanks & regards,
Alphonsa Abraham

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 09:50 PM
Hi @Alphonsa Abraha ,
What is this Form? is this on the portal?do you have assignment group field on the same form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 09:53 PM
HI @Alphonsa Abraha ,
I trust you are doing great.
To display all the members of groups on a particular form in ServiceNow, you can follow these steps:
Create a new UI macro or modify an existing one to retrieve the group members. A UI macro is a reusable UI component in ServiceNow. You can use it to encapsulate the logic and design for displaying the group members.
Define the UI macro by navigating to "System UI" -> "UI Macros" in the ServiceNow application menu. Click on "New" to create a new UI macro.
Give a suitable name to the UI macro, such as "GroupMembers", and provide a description if needed.
In the UI macro script, write the necessary code to retrieve the group members. Use the GlideSystem API and GlideRecord API to query the system tables. Here's an example code snippet:
<?xml version="1.0" encoding="utf-8"?>
<xml>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g2:evaluate var="groupMembers">
var groupSysID = "${sys_id}"; // Replace sys_id with the actual sys_id of the group
var members = [];
var groupGr = new GlideRecord('sys_user_group');
if (groupGr.get(groupSysID)) {
var memberGr = groupGr.getMembers();
while (memberGr.next()) {
members.push(memberGr.getValue('user'));
}
}
members;
</g2:evaluate>
<j2:forEach var="member" items="${groupMembers}">
<p>${member}</p>
</j2:forEach>
</j:jelly>
</xml>
Save the UI macro and exit the editor.
Now, go to the form where you want to display the group members. Edit the form and add the UI macro you created in step 4.
Locate the field or section on the form where you want the group members to appear. Edit the field or section properties and choose the UI macro you created as the formatter.
Save the form and test it by opening a record that corresponds to the form. You should now see the list of group members displayed on the form.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 09:53 PM
Hi, can you clarify the business drivers behind this requirement?
You could use an embedded list on the form, a related list at bottom of form, or potentially add a list collector to the form and populated with the group members via client script or BR; The big question is why? what value does this provide? All solutions have pros\cons but with no clear requirement details the community can only guess at your intention\need.