We are using dotCMS 1.7a and I am having difficulty getting the email addresses of users in the Administrator role.
This SQL works:
select user_.emailaddress
from user_
INNER JOIN users_roles
ON users_roles.userid = user_.userid
INNER JOIN role_
ON users_roles.roleid = role_.roleid
where role_.name = 'Administrator';
But this Velocity code doesn't:
<p>Start</p>
#set($found = $cmsuser.searchUsersAndUsersProxy(null, null, null, [], true,
["Administrator"], true, null, 1, 0))
<p>Finish</p>
<p>Found: $found [$found.size()].</p>
#set($theUsers = $found.get("users"))
<p>Got theUsers: $theUsers [$theUsers.size()].</p>
The output of the above code is:
Start
Finish
Found: {total=22, usersProxy=[], users=[], groupNames=[], roleNames=[]} [5].
Got theUsers: [] [0].
What is going wrong? Any help would be most appreciated!
Rob :)
Got the answer - thanks to Paul P. :)
#set($found = $cmsuser.searchUsersAndUsersProxy(null, null, null, [], false,
["Administrator"], true, null, 1, 1000))
<p>Found $found.get("users").size() Administrator users.</p>
#set($theUsers = $found.get("users"))
#foreach ($user in $theUsers)
$user.fullName ($user.emailAddress)<br>
#end
Note 1. Javadocs for $cmsuser.searchUsersAndUsersProxy() show the parameters for that method.
Note 2. In this case (dotCMS 1.7) the pageSize arg (final int - number of element to show in the page) doesn't follow dotCMS convention i.e. 0 really does mean 0! Normally it means "no limit".
Note 3. The fifth parameter (showUserGroups) should be false or I will get duplicates (as in a full join).