CRM2011 RetrieveMultiple SOAP order format

Today I needed to apply an order expression to a SOAP RetrieveMultiple call in JavaScript. I searched high and low online but could only find examples without ordering (<a:Orders />). I used the SOAPLogger tool (see Microsoft Dynamics CRM SOAP Logger) found in the SDK (sdk\samplecode\cs\client\soaplogger) to capture a RetreieveMultiple call with ordering and I thought I’d post an example here to save the next person doing this some time.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <request i:type="a:RetrieveMultipleRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
        <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <b:key>Query</b:key>
            <b:value i:type="a:QueryExpression">
              <a:ColumnSet>
                <a:AllColumns>false</a:AllColumns>
                <a:Columns xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                  <c:string>accountid</c:string>
                  <c:string>name</c:string>
                </a:Columns>
              </a:ColumnSet>
              <a:Criteria />
              <a:Distinct>false</a:Distinct>
              <a:EntityName>account</a:EntityName>
              <a:Orders>
                <a:OrderExpression>
                  <a:AttributeName>name</a:AttributeName>
                  <a:OrderType>Ascending</a:OrderType>
                </a:OrderExpression>
              </a:Orders>
              <a:NoLock>false</a:NoLock>
            </b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil="true" />
        <a:RequestName>RetrieveMultiple</a:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>

CRM2011 SOAP Money field create/update format

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was ‘Error in line 1 position 674. Element ‘http://schemas.datacontract.org/2004/07/System.Collections.Generic:value&#8217; contains data from a type that maps to the name ‘http://www.w3.org/2001/XMLSchema:Money&#8217;. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name ‘Money’ and namespace ‘http://www.w3.org/2001/XMLSchema&#8217;.’. Please see InnerException for more details.

I recently received the error above when attempting to perform a JavaScript CreateRequest on a money field in CRM2011. I found many people experiencing the same issue without any satisfactory resolution.

The following is the correct way to format a Money field in a SOAP create or update request in CRM2011.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">',
  <s:Body>
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <request i:type="a:CreateRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
        <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <b:key>Target</b:key>
            <b:value i:type="a:Entity">
              <a:Attributes>
                <a:KeyValuePairOfstringanyType>
                  <b:key>annualincome</b:key>',
                  <b:value i:type="a:Money">
                    <a:Value>1000</a:Value>
                  </b:value>
                </a:KeyValuePairOfstringanyType>
              </a:Attributes>
              <a:EntityState i:nil="true" />
              <a:FormattedValues />
              <a:Id>00000000-0000-0000-0000-000000000000</a:Id>
              <a:LogicalName>Contact</a:LogicalName>
              <a:RelatedEntities />
            </b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil="true" />
        <a:RequestName>Create</a:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>