The Setup
I have a list with 2 extra columns.
- Target Audience: Choice (Relevant/Everyone)
- Tags: Managed Metadata field (multiple)
When I choose in the "Target Audience" field "Everyone", this item should be retrieved when using a SPQuery on the list.
When I choose in the "Target Audience" field "Relevant", this item should be retrieved only if the user has the same tags linked to his userprofile.
The Problem
Retrieving the userproperties and tags works, but when I execute the Query on the list, I retrieve the wrong expected result...
Here is an example of the SPQuery that is generated.
<Where>
<Or>
<Eq>
<FieldRef Name='TargetAudience' />
<Value Type='Choice'>Everyone</Value>
</Eq>
<And>
<Eq>
<FieldRef Name='TargetAudience' />
<Value Type='Choice'>Relevant</Value>
</Eq>
<In>
<FieldRef LookupId='TRUE' Name='Tags' />
<Values>
<Value Type='Integer'>1</Value>
<Value Type='Integer'>3</Value>
<Value Type='Integer'>4</Value>
</Values>
</In>
</And>
</Or>
</Where>
Does anything see what is wrong with it?
In my case I only retrieve the items where "Tags" is filled with a value, even when "Everyone" is selected. Otherwise, the item is never retrieved.
Data Examples
- TargetAudience: Everyone, Tags: <None>
- TargetAudience: Relevant, Tags: <None>
- TargetAudience: Everyone, Tags: 1
- TargetAudience: Relevant, Tags: 1
In this example, only item 3,4 are retrieved. --> Items 1,3,4 should be returned instead!