cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

Hi Forum!

I am trying to query a list called Systems using a filter against the system owner.  My problem - I received a new requirement that System Owner which is a person field, needs to allow multiple selections.

Before this, my query was easy - filter by systemowner  ID.  Now I'm not sure what to do.  I can construct a comma (or semi colon, or whatever) delimited list of user Ids of the owners, but I don't know how to use that in my where clause.  I have tried a comma delimited and semicolon delimited list of IDs in a query that looks like:

<Query>
<Lists>
<List ID="{235E8F30-0228-4ED9-897E-139662390380}" />
</Lists>
<ViewFields>
<FieldRef Name="ID" />
</ViewFields>
<Where>
<And>
<Eq>
<FieldRef Name="ApplicationState" />
<Value Type="Text">Active</Value>
</Eq>
<Eq>
<FieldRef Name="ApplicationOwner" LookupId="TRUE" />
<Value Type="User">{WorkflowVariable:currAppOwnerIdMulti}</Value>
</Eq>
</And>
</Where>
</Query>

where the variable currAppOwnerIdMulti is the list of Ids.  This query works if only 1 id is present. It does not work with 2 when they are comma or semicolon delimited.  Does my requirement make sense? Is it even possible?  

Thanks,

Erin

Labels: (1)
Tags (1)
0 Kudos
Reply
8 Replies
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution
0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

I can't get this to work - my ValuesList variable prints out to this:

error is 'Failed to query list data. Value does not fall within the

expected range.

I changed the string builder to remove the last, empty Value tag and

receive the same error.

I'm getting the list of users by querying the list in question, setting the

person/group field to a collection variable , say col1 - then I loop

through col1 for each result, currentUser, add the currentUser to a new

collection col2. col2 is what is being referenced in the build string for

the ValuesList

0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

could you post a sample what output do you get from build string action?

resp. how does your overall query list action look like afterwards.

0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

Strange, the email response stripped that part out.  This is the result of the build string

<Value Type='User'>i:0#w|aesp\555555555.ctr</Value><Value Type='User'></Value>

0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

I figured it out - I hadn't noticed that in the query list action you have to deselect xml encode.  So now I don't get an error, but the filter isn't working - my query is returning 0 items when i know that isn't true. I tried removing the empty value tag at the end (which is needed for multi values so this couldn't be a fix regardless) but that didn't make a difference

My caml query is

<Query>

<Lists>

<List ID="{555E5F55-5555-5ED-55E-555555555}"/>

</Lists>

<ViewFields>

   <FieldRef Name="ID"/>

</ViewFields>

<Where>

<In>

<FieldRef Name="SystemOwner"/>

<Values>{WorkflowVariable:ValuesList}</Values>

</In>

</Where>

</Query>

(obvi not the real list id, i typed this manually and didn't want to bother copying the real id)

0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

What's your person or group field setting for 'Show field'?

if you use default 'Name with presence' then you should provide into the filter either user IDs ...

.... or user display names ...

... just like you did for person field with single entry.

0 Kudos
Reply
Highlighted
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

I did end up getting this to work!  I take the current multi person field and save the ID as user Id - Number.  Then the where clause in CAML is 

<Eq>

   <FieldRef Name='SystemOwner' LookupId='True'/>

      <Value Type='UserMulti'>{WorkflowVariable:idVar}</Value>

</Eq>

Thanks for working with me on this, Marian

0 Kudos
Reply
Workflow Hero

Re: How do I query a list using a filter where the filter field is a person field that can contain many?

Jump to solution

great!

please select and mark a correct answer to close the thread.

0 Kudos
Reply