locked
SOAP CreateRequest with related entities RRS feed

  • Question

  • Hi

    I'm attempting to create an entity and specify its relations at the same time, using the CreateRequest SOAP request.  I've got a correctly-formatted SOAP request which Dynamics Online does not balk at, which creates the entity (an opportunity in my case), but does not have the associated entities (account, campaign) specified.  I'd rather be able to generate the entire record at once without having to manually specify related entities after the initial entity has been created.

    The documentation for these requests is absolutely shocking, and I've spent quite a decent chunk of time trying to find a solution.

    I'm using EntityReferences in my XML to specify the referenced entities, which Dynamics Online accepts without issue.

    Any help would be greatly appeciated.

    Thanks!

    Dave

    Wednesday, June 4, 2014 1:53 PM

All replies

  • Can you post your XML? Which exact fields (logical name) you are trying to set?

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, June 4, 2014 2:00 PM
  • Here is a link to the XML I'm sending: https://gist.github.com/anonymous/8c3c85da64419978874a

    I must state that I'm really looking for a description of the correct way to do it (as I've not even found that outlined on the web) :)

    Wednesday, June 4, 2014 2:05 PM
  • Hi,
    I checked your code, you are using an execute for making a CreateRequest, I don't know why your request doesn't set up the lookups (assuming the guid values are correct of course), but I can share an xml soap request of the Create request, here the code adapted with your values, hope it helps.

    <soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
    	<soap:Body>
    		<Create xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
    			<entity xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>
    				<a:Attributes xmlns:b='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>
    					<a:KeyValuePairOfstringanyType>
    						<b:key>name</b:key>
    						<b:value i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>New Opportunity</b:value>
    					</a:KeyValuePairOfstringanyType>
    					<a:KeyValuePairOfstringanyType>
    						<b:key>parentaccountid</b:key>
    						<b:value i:type='a:EntityReference'>
    							<a:Id>b39facb8-bae1-e311-8ba9-d89d6764e58c</a:Id>
    							<a:LogicalName>account</a:LogicalName>
    							<a:Name i:nil="true" />
    						</b:value>
    					</a:KeyValuePairOfstringanyType>
    					<a:KeyValuePairOfstringanyType>
    						<b:key>campaignid</b:key>
    						<b:value i:type='a:EntityReference'>
    							<a:Id>638cdd8a-b3e1-e311-8ba9-d89d6764e58c</a:Id>
    							<a:LogicalName>campaign</a:LogicalName>
    							<a:Name i:nil="true" />
    						</b:value>
    					</a:KeyValuePairOfstringanyType>
    					<a:KeyValuePairOfstringanyType>
    						<b:key>ownerid</b:key>
    						<b:value i:type='a:EntityReference'>
    							<a:Id>579a54d8-9792-47be-a742-c0e54fd457de</a:Id>
    							<a:LogicalName>systemuser</a:LogicalName>
    							<a:Name i:nil="true" />
    						</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:LogicalName>opportunity</a:LogicalName>
    				<a:RelatedEntities xmlns:b='http://schemas.datacontract.org/2004/07/System.Collections.Generic' />
    			</entity>
    		</Create>
    	</soap:Body>
    </soap:Envelope>


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Wednesday, June 4, 2014 7:55 PM
  • Thanks, but I've already tried that - with the same result.  I've tried every permutation of Create and Execute-ing CreateRequests, and they all function the same - the base entity is created without issue, but its relations are not present.

    Thanks for looking, however.  If you get any brain storms please let me know :)

    Cheers,

    Dave

    Thursday, June 5, 2014 7:04 AM
  • Hi Dave,

    i checked the field names and inside opportunity there isn't an accountid field, but a parentaccountid field. I changed my code, try with the correct field now if at least one lookup is filled correctly.


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, June 5, 2014 7:47 AM
  • This very well could be an ID10T / PEBKAC issue ;)

    I can't thank you enough for your insight - sometimes it takes a fresh pair of eyes to get to the bottom of something as strange as Dynamics' SOAP API!

    Cheers,

    Dave

    Thursday, June 5, 2014 8:36 AM