Post

1 follower Follow
0
Avatar

Using Link Entity in query

Hello,

 

I am wondering how i can use links in my query? For example, i need to get list of users, which belongs to group "A" or group "B". I see that can be done using entities User, UserGroup and GroupHierarchyLink. But how can i combine them into one query?

 

Please advice, 

Thank you

Oleg Savich Answered

Please sign in to leave a comment.

4 comments

0
Avatar

Hi Oleg.

Basically you should query the GroupMembershipLink. To get the group information add Container.xxx in the Fields property. Similarly, add Member.xxx for the user information.

You could filter the required groups by a direct condition on the group id, or a filter query (using In operator). Both should be performed on the Container field. Surely, I have a sample for all of this:

EntityQuery

 

 

groupMemberShip = new EntityQuery

            {

                TypeName =

 

"GroupMembershipLink",

                Fields =

 

new string[] { "Container.Name", "Member.Name" },

                Where =

 

new Or

                {

                    Conditions =

 

new Compare[]

                    {

                       

 

new Compare

                        {

                            LeftExpression =

 

new FieldExpression {FieldName="Container"},

                            Operator =

 

Operator.Equal,

RightExpression =

 

new ConstantExpression {Value = new EntityId {TypeName="UserGroup", Value= "dd5ed193-1aa7-4151-b424-f757af66959b"}}

                        },

                       

 

new Compare

                        {

                            LeftExpression =

 

new FieldExpression {FieldName = "Container"},

                            Operator =

 

Operator.In,

                            RightExpression =

 

new QueryExpression

                            {

                                Query =

 

new EntityQuery

                                {

TypeName =

 

"UserGroup",

                                    Where =

 

new Compare

                                    {

                                        LeftExpression =

 

new FieldExpression {FieldName="Name"},

                                        Operator =

 

Operator.Contains,

RightExpression =

 

new ConstantExpression {Value = "sub"}

                                    }

                                }

                            }

                        }

                    }

                }

            };

 

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hi Ophir,

Thank you for quick answer,

I have one more question if possible. The query result is GroupMembershipLink. How i can use this result as condition for another query? For example, get tasks which have some user field (lets say QA) in sample provided?

 

The topic of using [Something]Link results as condition for query not clear for me.

 

Thank you!

Oleg

Oleg Savich 0 votes
Comment actions Permalink
0
Avatar

Hi Oleg,

I don't think you can use the results directly.

You'll have to extract the EntityId_s of the group members from the result (make sure your query fields include "member" or "member.<some field>" to be used within a condition of a second query on _Workitem or RegularResourceLink.

Note: when you specify a referenced entity in the Fields (e.g. "member.name" in the above sample), the query result will contain a FieldValue with a field name <the reference field> (e.g. "Member") and a value of type GenericEntity. That GenericEntity contains the Id of the referenced entity + any fields requested for it (e.g. "name") in the _Values _collection.

 

Hope this helps

Ophir Kenig 0 votes
Comment actions Permalink