1

I'm sure I'm missing something simple here, but I can't seem to figure it out. I have two lists:

Rating Sections:

  1. Title - Single line of text

Rating Categories:

  1. Title - Single line of text
  2. Rating Section - Lookup to Title of Rating sections

I am attempting to use CSOM to join and query the two lists. Each lists only contains 10 items so I shouldn't be hitting any sort of size limit. My code is as follows:

using (var spContext = new ClientContext("http://myserver/jointest")) {
    var list = spContext.Web.Lists.GetByTitle("Rating Categories");
    var query = new CamlQuery {
        ViewXml = @"
<View>
    <ViewFields>
        <FieldRef Name='ID' />
        <FieldRef Name='Title' />
        <FieldRef Name='Rating_x0020_Section' />
        <FieldRef Name='RatingSectionTitle' />
    </ViewFields>
    <Joins>
        <Join Type='INNER' ListAlias='RatingSections'>
            <Eq>
                <FieldRef Name='Rating_x0020_Section' RefType='Text' />
                <FieldRef List='Rating Sections' Name='Title' />
            </Eq>
        </Join>
    </Joins>
    <ProjectedFields>
        <Field Name='RatingSectionTitle' Type='Lookup' List='RatingSections' ShowField='Title' />
    </ProjectedFields>
</View>"
            };
    var listItems = list.GetItems(query);
    spContext.Load(listItems);
    spContext.ExecuteQuery();
}

Every time I run the code, I get the exception "Value does not fall within expected range". Any idea what I have wrong here?

Edit: I've also tried it with the following values:

<FieldRef Name='Rating_x0020_Section' RefType='Id' />
<FieldRef List='Rating Sections' Name='ID' />

Which still throws the same error. I've also tried every variation of capitalizing ID in both FieldRefs just in case it was case sensitive.

  • could you please recheck your field types. This exception might occur due to breaking the limitation "Moreover, the field in the primary list must be a Lookup type field that looks up to the field in the foreign list." according to msdn.microsoft.com/en-us/library/… – Celophysis Jun 7 '18 at 12:47
  • The best I can tell, the field types are correct. – DrewB Jun 7 '18 at 13:06
1

Finally found the answer. The List in the second FieldRef has to be the same as the ListAlias, so it should be:

<FieldRef List='RatingSections' Name='ID' />

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.