I am trying to retrieve data from SharePoint list via REST API with CAML Query join but having issues with query (not sure if its limitation in SharePoint or something wrong in query). I have below two list in SharePoint 2013 (on-prem) server.

Customers
---------------
Id
Name
TotalOrder
ExpectedOrderTotal
PercentageOrdered (Calculated field based on TotalOrder & ExpectedOrderTotal : = TotalOrder / ExpectedOrderTotal)

Orders
----------------
Id
Customer (Lookup from Customers)
DateOrderPlace
Amount
Product (Lookup from Products list)

First issue: Not getting fields from joined list.

I am trying to retrieve fields from Customers and Orders list via CAML Query join on Order List with below query.

<View>
   <Joins>
      <Join Type='INNER' ListAlias='Customers'>
         <Eq>
            <FieldRef Name='Customer' RefType='Id' />
            <FieldRef List='Customers' Name='ID' />
         </Eq>
      </Join>
   </Joins>
   <ProjectedFields>
      <Field ShowField='Id' Type='Lookup' Name='CustomerId' List='Customers' />
      <Field ShowField='Name' Type='Lookup' Name='CustomerName' List='Customers' />
      <Field ShowField='TotalOrder' Type='Lookup' Name='CustomerTotalOrder' List='Customers' />
      <Field ShowField='PercentageOrdered' Type='Lookup' Name='CustomerOrderPerc' List='Customers' />
   </ProjectedFields>
   <ViewFields>
       <FieldRef Name='CustomerId'/>
        <FieldRef Name='CustomerName'/>
        <FieldRef Name='CustomerTotalOrder'/>
        <FieldRef Name='CustomerOrderPerc'/>
        <FieldRef Name='Id'/>
        <FieldRef Name='DateOrderPlace'/>
        <FieldRef Name='Amount'/>
   </ViewFields>
</View>

Query works but it only returns fields from Order list, i.e Id, DateOrderPlace and Amount. It doesn't return fields from Customers list, i.e CustomerId, CustomerName, CustomerTotalOrder and CustomerOrderPerc.

Second problem: cannot filter on Calculated field from joined list

With above same query, even though its not returning fields from Customers list, I can filter on those fields but except calculated field (CustomerOrderPerc). Filter with order amount : (works)

 <Query>
      <Where>
             <Gt>
                <FieldRef Name='CustomerTotalOrder' />
                <Value Type='Number'>100</Value>
            </Gt>
      </Where>
   </Query>

Above works fine (except that it doesn't return previously mentioned fields from customer list in response) and it only returns orders linked to customer that has total order more than 100. But when run below query to filter by calculated field 'CustomerOrderPerc' it fails.

 <Query>
      <Where>
             <Gt>
                <FieldRef Name='CustomerOrderPerc' />
                <Value Type='Number'>0.8</Value>
            </Gt>
      </Where>
   </Query>

Error:

"error":{
    "code": "-2147024809, System.ArgumentException",
     "message":{
           "lang": "en-US",
           "value": "Value does not fall within the expected range."
     }
}

Any help would be much appreciated.

Thanks All

0

There are 0 best solutions below