This is my very first script in Alfresco since I learn its web script a couple weeks ago. I intend to write all my learning process in this blog as my online documentation :)

getMembersOfGroup.get.desc.xml
<webscript>
	<shortname>Get a group's members</shortname>
	<description>Get all the members of a group</description>
	<url>/get/members/of/group/?groupName={groupName}</url>
	<format default="html" />
	<authentication>admin</authentication>
	<transaction>required</transaction>
</webscript>

getMembersOfGroup.get.html.ftl
<html>
<body>
<table border="1">
	<tr>
		<td>#</td><td>Username</td><td>Email</td><td>First Name</td><td>Last Name</td>
	</tr>
	<#list users as u>
	<tr>
		<td>${u_index + 1}</td><td>${u.properties["cm:userName"]}</td>
		<td>${u.properties["email"]}</td><td>${u.properties["firstName"]}</td>
		<td>${u.properties["lastName"]}</td>
	</tr>
	</#list>
</table>
</body>
</html>

getMembersOfGroup.get.js
// get the group name from args
var groupName = args.groupName;
// add "GROUP_" prefix to groupName
var groupSource = people.getGroup('GROUP_' + groupName);

if (groupSource) {
	// get the members of the group
	var groupMembers = people.getMembers(groupSource);

	model.users = groupMembers;
}

Advertisement