Dynamics CRM 2011 SOAP RetrieveMultiple query ignoring criteria

dynamics-crm-2011, php, soap

Solution

There was a few things wrong with the above query. (in particular some of my aliases were confused). As suggested by Jeff Xiong the SOAPLogger helped me.

The criteria was also incorrect. Working soap below:

<RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <query xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" i:type="b:QueryExpression">
      <b:ColumnSet>
         <b:AllColumns>false</b:AllColumns>
         <b:Columns xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <c:string>firstname</c:string>
            <c:string>emailaddress1</c:string>
         </b:Columns>
      </b:ColumnSet>
      <b:Criteria>
         <b:Conditions>
            <b:ConditionExpression>
               <b:AttributeName>emailaddress1</b:AttributeName>
               <b:Operator>Equal</b:Operator>
               <b:Values xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                  <c:anyType xmlns:d="http://www.w3.org/2001/XMLSchema" i:type="d:string">test@test.com</c:anyType>
               </b:Values>
            </b:ConditionExpression>
         </b:Conditions>
         <b:FilterOperator>And</b:FilterOperator>
         <b:Filters />
      </b:Criteria>
      <b:Distinct>false</b:Distinct>
      <b:EntityName>contact</b:EntityName>
      <b:LinkEntities />
      <b:PageInfo>
         <b:Count>250</b:Count>
         <b:PageNumber>1</b:PageNumber>
         <b:PagingCookie i:nil="true" />
         <b:ReturnTotalRecordCount>false</b:ReturnTotalRecordCount>
      </b:PageInfo>
   </query>
</RetrieveMultiple>

Problem

I am connecting to Dynamics CRM 2011 Online using PHP and SOAP and have come across an issue. The following RetrieveMultiple ignores my criteria and returns all records. All I want is any contacts that have 'test@test.com' as their email address. Could someone tell me what is wrong with my Criteria/Condition below? Thanks! ``` <RetrieveMultiple xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"> <query xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" i:type="b:QueryExpression"> <b:ColumnSet> <b:AllColumns>false</b:AllColumns> <b:Columns xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <c:string>firstname</c:string> </b:Columns> </b:ColumnSet> <b:Criteria> <b:Conditions> <b:Condition> <b:AttributeName>emailaddress1</b:AttributeName> <b:Operator>Equal</b:Operator> <b:Values> <b:Value i:type="xsd:string">test@test.com</b:Value> </b:Values> </b:Condition> </b:Conditions> <b:FilterOperator>And</b:FilterOperator> <b:Filters /> </b:Criteria> <b:Distinct>false</b:Distinct> <b:EntityName>contact</b:EntityName> <b:LinkEntities /> <b:PageInfo> <b:Count>250</b:Count> <b:PageNumber>1</b:PageNumber> <b:PagingCookie i:nil="true" /> <b:ReturnTotalRecordCount>false</b:ReturnTotalRecordCount> </b:PageInfo> </query> </RetrieveMultiple> ```

Original source