0

I am trying to retrieve all Customer Contracts which Customer Master has Procurement Relevant = True

I used CSOM to communicate with SharePoint 2010 to retrieve list items and used CAML query to filter and join lists .

List list = web.Lists.GetByTitle("Customer Contracts");
var itemColl = await Task.Run<ListItemCollection>(() =>
                {
                    CamlQuery query =//CAMEL query showed below 

                    ListItemCollection coll = list.GetItems(query);
                    clientContext.Load(coll);
                    // Execute the query to the server
                    clientContext.ExecuteQuery();
                    return coll;
                });

It raised the following exception when query executed

Exception : ( Microsoft.SharePoint.Client.ServerException was unhandled by user code HResult=-2146233088 Message=Value does not fall within the expected range. Source=Microsoft.SharePoint.Client.Runtime ServerErrorCode=-2147024809 ServerErrorTypeName=System.ArgumentException )

Check the following CAML query :

<View Scope="RecursiveAll">
    <Query>
        <Where>
            <Eq>
                <FieldRef Name="CustomerProcurementRelevant" />
                <Value Type="String">True</Value>
            </Eq>
        </Where>
    </Query>
    <Joins>
        <Join Type="INNER" ListAlias="Customer Master">
            <Eq><FieldRef Name="Customer_x0020_ID" RefType="Id" />
                <FieldRef List="Customer Master" Name="ID" />
            </Eq>
        </Join>
    </Joins>
    <ProjectedFields>
        <Field Name="CustomerProcurmentRelevant" Type="Lookup" List="Customer Master" ShowField="Procurement_x0020_Relevant" />
    </ProjectedFields>
    <ViewFields>
        <FieldRef Name="Modified" /><FieldRef Name="Customer_x0020_ID" /><FieldRef Name="Title" /><FieldRef Name="ES_x0020_Service_x0020_Segment" />
        <FieldRef Name="ADE_x002f_ADM" /><FieldRef Name="Account_x0020_Controlling" /><FieldRef Name="Contract_x0020_terminated" /><FieldRef Name="Country" />
        <FieldRef Name="CustomerProcurmentRelevant" />
    </ViewFields>
    <RowLimit>999999</RowLimit>
</View>
1

You should pass a SPQuery object to the GetItems method. In the query attribute you have to put just the <Query> tag. Use:

SPQUery query = new SPQuery();
query.Query = "" //your <Query>...</Query> tag
//for all your view field
query.ViewFields ="<FieldRef Name='ID'/>"

To specify the row limit use:

query.RowLimit = 100;

To specify the scope:

query.ViewAttributes = "Scope=\"RecursiveAll\""

To specify Joins:

query.Joins = "";

and

query.ProjectedFields="";

Take a look to these links:

JOINS AND PROJECTIONS IN SHAREPOINT 2010
CAML query join

  • Thanks @NK SP for your reply but why I need to re assign view fields and row limit as I did assign them in CAML query showed . Regarding links you showed I think these limitation not applied with my case . By the ways this code worked successfully before but without last update which is join and projected fields . – Mohammed Thabet Apr 26 '15 at 17:06

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.