The Setup

I have a list with 2 extra columns.

  1. Target Audience: Choice (Relevant/Everyone)
  2. 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.

        <FieldRef Name='TargetAudience' />
        <Value Type='Choice'>Everyone</Value>
            <FieldRef Name='TargetAudience' />
            <Value Type='Choice'>Relevant</Value>
            <FieldRef LookupId='TRUE' Name='Tags' />
                <Value Type='Integer'>1</Value>
                <Value Type='Integer'>3</Value>
                <Value Type='Integer'>4</Value>

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!

  • You are expecting 1,3 & 4 – Gaurravs Nov 16 '15 at 8:33
  • Correct, 1,3,4 should be retrieved. – Ruben Herman Nov 16 '15 at 8:36
  • break the query and see the results in both the cases, try only for TargetAudience: Everyone in 1 query & the other block later on – Gaurravs Nov 16 '15 at 8:38
  • Breaking them into seperate cases didn't help me either. Everything works as expected, until the last queries (children of "Or") are merged, then I have the wrong result. And I can't imagine that the problem lies with the Or wrapped around them... – Ruben Herman Nov 16 '15 at 8:54
  • I'm guessing you have Allow Multiple on your Tags column? Seen som strange behavior before with CAML and Allow Multiple on managed metadata. If you could test without allow multiple on, just to see if that is the reason. I don't have a fix for it, just the reason maybe :) – Anders Aune Nov 16 '15 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.