Search code examples
phpapisoapdynamics-crmdynamics-crm-online

Send picklist value to Dynamics crm online to create lead using soap php


I am trying to create a lead in crm 365 online using soap in php. I can create a lead successfully by sending soap request but I want to send leadsource as well and it's a picklist in crm. Here is my code in php. Not sure which datatype to use, int32 or picklist, but both are not working.

<b:KeyValuePairOfstringanyType>
            <c:key>leadsourcecode</c:key>
            <c:value i:type="d:OptionSetValue" xmlns:d="http://www.w3.org/2001/XMLSchema">100000010</c:value>
        </b:KeyValuePairOfstringanyType>';

I am getting this error:

Sendera:DeserializationFailedThe 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:entity. The InnerException message was 'Error in line 22 position 82. Element 'http://schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data from a type that maps to the name 'http://www.w3.org/2001/XMLSchema:OptionSetValue'. 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 'OptionSetValue' and namespace 'http://www.w3.org/2001/XMLSchema'.'. Please see InnerException for more details.

Solution

  • You need to have a capital V for the inner value tag. Here is code that works that I use to update the status reason, modify as appropriate. Also, the SOAP endpoint is deprecated, you should move to the WebAPI

    request += "<a:KeyValuePairOfstringanyType>";
    request += "<c:key>Status</c:key>";
    request += "<c:value i:type=\"a:OptionSetValue\">";
    request += "<a:Value>" + 2 + "</a:Value>";
    request += "</c:value>";
    request += "</a:KeyValuePairOfstringanyType>";