Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > UsersViewer - Order by Roles? View modes: 
User avatar
Member
Member
dfurler-liv.asn - 7/23/2012 9:26:39 PM
   
UsersViewer - Order by Roles?
Hello,

I am using the UserViewer webpart to display a group of users belonging to a certain role.

The current WHERE clause being something like:

UserID IN (select UserID FROM CMS_UserRole where RoleID = (select RoleID from CMS_Role where RoleDisplayName = 'Role A'))

I also want to display users (using the same webpart) that belong to a different role, and show those users first. Is this possible with one WHERE or ORDER BY in the one webpart?

To make my example more concrete, I basically want to list members of a group, but have the "leader" of that group be listed first. The "leader" belongs to a "leader" role.

Thanks!
David

User avatar
Kentico Support
Kentico Support
kentico_janh - 7/26/2012 1:49:09 AM
   
RE:UsersViewer - Order by Roles?
Hello,

Regrettably, this can't be done by using one User Viewer web part, because there is no link to a role in the CMS_User table, so the easiest way how to achieve it is by placing two User Viewer web parts when one displays users who belong to the Role A and to the Leader role and the other displays user who belong just to the Role A.

Best regards,
Jan Hermann

User avatar
Member
Member
dfurler-liv.asn - 7/26/2012 1:58:18 AM
   
RE:UsersViewer - Order by Roles?
Hi Jan,

Drats. Thank you very much for your answer regardles though.

Regards,
David

User avatar
Member
Member
dfurler-liv.asn - 7/26/2012 2:27:38 AM
   
RE:UsersViewer - Order by Roles?
For anyone else that comes along and needs to do the same thing, below are the where clauses (examples):

First one displays members of "Role A" and "Role B" :

UserID IN (select UserID FROM CMS_UserRole where RoleID = (select RoleID from CMS_Role where RoleDisplayName = 'Role A')) AND UserID IN (select UserID FROM CMS_UserRole where RoleID = (select RoleID from CMS_Role where RoleDisplayName = 'Role B'))

Second webpart to display members of "Role B" who are not members of "Role A":

UserID IN (select UserID FROM CMS_UserRole where RoleID = (select RoleID from CMS_Role where RoleDisplayName = 'Role B')) AND NOT UserID IN (select UserID FROM CMS_UserRole where RoleID = (select RoleID from CMS_Role where RoleDisplayName = 'Role A'))

Not sure if that is most efficient, but it works.

Regards,
David