Home > Forum > General > Finding the manager using BPS Groups

Finding the manager using BPS Groups
0

I've got following problems - we are using AD as an authentication tool, but because of quite complex, matrix organizational scheme I cannot use a supervisor data from AD, because (depending on the project) the same user can have two different managers). So I figured out, that I will be using BPS Groups next to AD:
1. I've got User A, Manager A and Manager B
2. I've got groups Managers, Project A & Project B
3. User A belongs to groups Project A and Project B.
4. Manager A is in Project A and Manager B is in group Project B.
If we have e.g. expense acceptance workflow and depending on which expense belongs to which project, how can I find with query the manager of Project A or manager of Project B.

MVP

Hi Przemysław,

if I haven't missed anything, would it be enaugh to select a user from the project group, who also belongs to the managers group?
Assuming, that you can indicate in the workflow a group for a given project
eg. expenses belongs to Project A -> search in Project A group

If so, it can be done based on the CacheOrganizationStructure and CacheOrganizationStructureGroupRelation table.

So we can use queries like this, first to return users from a group:

SELECT usr.COS_BpsID, usr.COS_DisplayName

FROM CacheOrganizationStructure gr
join CacheOrganizationStructureGroupRelations rel ON gr.COS_ID = rel.COSGR_GroupID
join CacheOrganizationStructure usr ON rel.COSGR_UserID = usr.COS_ID

WHERE gr.COS_BpsID = 'Project A' AND usr.COS_IsActive = 1

I use it as Table-valued function, and Scalar function to determine if user belongs to group:

return (
select
case when exists (
select *
from [dbo].[CacheOrganizationStructure] u
join [dbo].[CacheOrganizationStructureGroupRelations] gr
on gr.COSGR_UserID = u.COS_ID
join [dbo].[CacheOrganizationStructure] g
on g.COS_ID = gr.COSGR_GroupID
where u.cos_bpsid = 'User login' and g.COS_BpsID = 'Managers group id'
)
then 1
else 0
end
)

combining them, we can return users from the Project A group, who also belongs to the Managers group:

SELECT COS_BpsID
from dbo.getGroupUsers('Project A group id')
WHERE dbo.IsUserInGroup(COS_BpsID,'Managers group id')

Just an example to give some idea :)

In reply to: Sebastian Gębuś

Hi Przemysław,

if I haven't missed anything, would it be enaugh to select a user from the project group, who also belongs to the managers group?
Assuming, that you can indicate in the workflow a group for a given project
eg. expenses belongs to Project A -> search in Project A group

If so, it can be done based on the CacheOrganizationStructure and CacheOrganizationStructureGroupRelation table.

So we can use queries like this, first to return users from a group:

SELECT usr.COS_BpsID, usr.COS_DisplayName

FROM CacheOrganizationStructure gr
join CacheOrganizationStructureGroupRelations rel ON gr.COS_ID = rel.COSGR_GroupID
join CacheOrganizationStructure usr ON rel.COSGR_UserID = usr.COS_ID

WHERE gr.COS_BpsID = 'Project A' AND usr.COS_IsActive = 1

I use it as Table-valued function, and Scalar function to determine if user belongs to group:

return (
select
case when exists (
select *
from [dbo].[CacheOrganizationStructure] u
join [dbo].[CacheOrganizationStructureGroupRelations] gr
on gr.COSGR_UserID = u.COS_ID
join [dbo].[CacheOrganizationStructure] g
on g.COS_ID = gr.COSGR_GroupID
where u.cos_bpsid = 'User login' and g.COS_BpsID = 'Managers group id'
)
then 1
else 0
end
)

combining them, we can return users from the Project A group, who also belongs to the Managers group:

SELECT COS_BpsID
from dbo.getGroupUsers('Project A group id')
WHERE dbo.IsUserInGroup(COS_BpsID,'Managers group id')

Just an example to give some idea :)

Hi, thank you very much for a clue. I think i've even managed to simplify the solution to:
SELECT usr.COS_BpsID, usr.COS_DisplayName

FROM CacheOrganizationStructure gr
join CacheOrganizationStructureGroupRelations rel ON gr.COS_ID = rel.COSGR_GroupID
join CacheOrganizationStructure usr ON rel.COSGR_UserID = usr.COS_ID

WHERE gr.COS_BpsID = 'Project A ID' AND usr.COS_IsActive = 1
INTERSECT
SELECT usr.COS_BpsID, usr.COS_DisplayName

FROM CacheOrganizationStructure gr
join CacheOrganizationStructureGroupRelations rel ON gr.COS_ID = rel.COSGR_GroupID
join CacheOrganizationStructure usr ON rel.COSGR_UserID = usr.COS_ID

WHERE gr.COS_BpsID = 'Managers Group ID' AND usr.COS_IsActive = 1

but another problem arise, I cannot create the data source, I've got an error like in attached picture.