I don’t know what I am doing wrong. All I am trying to do is to query CRM 2011 via PowerShell and SOAP. The following PowerShell script should return the Contact’s full name, but I get nothing. Any ideas??
Here is the PowerShell:
$xml = "<?xml version='1.0' encoding='utf-8'?>" $xml += "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" $xml += "<soap:Body>" $xml += "<Retrieve xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'>" $xml += "<entityName>contact</entityName>" $xml += "<id>12345678-1234-1234-1234-123456789012</id>" $xml += "<columnSet xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts' xsi:type='q1:ColumnSet'>" $xml += "<q1:Attributes>" $xml += "<q1:Attribute>fullname</q1:Attribute>" $xml += "<q1:Attribute>telephone1</q1:Attribute>" $xml += "</q1:Attributes>" $xml += "</columnSet>" $xml += "</Retrieve></soap:Body></soap:Envelope>" $url="http://crmserver.company.com/Organization/XRMServices/2011/Organization.svc/web" $http_request = New-Object -ComObject Msxml2.XMLHTTP $http_request.Open('POST', $url, $false) $http_request.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve"); $http_request.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); $http_request.setRequestHeader("Content-Length", $xml.length); $http_request.send($xml); $http_request.responseText
And here is the response:
$http_request.responseText <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body><RetrieveResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"> <RetrieveResult xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"> <a:KeyValuePairOfstringanyType> <b:key>accountid</b:key> <b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">12345678-1234-1234-1234-123456789012</b:value> </a:KeyValuePairOfstringanyType> </a:Attributes> <a:EntityState i:nil="true"/><a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/> <a:Id>12345678-1234-1234-1234-123456789012</a:Id><a:LogicalName>account</a:LogicalName> <a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/> </RetrieveResult> </RetrieveResponse>
I just don’t know what I am doing wrong. Why won’t the code return “fullname”, it is in the columnSet.
Update-2012-05-08:I have posted my question here, no answer yet
Update2-2012-05-05: I have posted and received and answer here on stack overflow. Big thanks to @JLattimer
Comments are closed.