问题
I have been able to create a contact in Dynamics WebAPI using a payload similar to this ...
{
"firstname": "asd",
"lastname": "asd"
}
I have been able to create an Account entity in Dynamics WebAPI using a payload similar to this ...
{
"name":"SOLE TRADER ORG",
"emailaddress1":"otbpostman1@post.com",
"telephone1":"07188888"
}
and a Connection entity between the two as follows ...
{
"record1roleid@odata.bind":"/connectionroles(1EB54AB1-58B7-4D14-BF39-4F3E402616E8)",
"record2roleid@odata.bind":"/connectionroles(35A23B91-EC62-41EA-B5E5-C59B689FF0B4)",
"record1id_contact@odata.bind":"/contacts(645f6455-8f1d-e911-a847-000d3ab4f534)",
"record2id_account@odata.bind":"/accounts(233cf761-8f1d-e911-a847-000d3ab4f534)"
}
According to this page I should be able to do a deep insert where I can atomically create all three in one request, I have tried the following ...
{
"record1roleid@odata.bind":"/connectionroles(1EB54AB1-58B7-4D14-BF39-4F3E402616E8)",
"record2roleid@odata.bind":"/connectionroles(35A23B91-EC62-41EA-B5E5-C59B689FF0B4)",
"record1id_contact": {
"firstname": "asd",
"lastname": "asd"
},
"record2id_account": {
"name":"SOLE TRADER ORG",
"emailaddress1":"otbpostman1@post.com",
"telephone1":"07188888"
}
}
... as well a bunch of variations around this but with no luck. I keep getting errors of type ...
"code": "0x80048210", "message": "Both objects being connected are missing."
Have I missed some key feature that means this is or is not possible?
回答1:
I think record2id_account is expecting a guid, so that wont work,
as the page you linked says, they do it on opportunity, they use
"An opportunity is created because it is defined as an object within an array that is set to the value of a collection-valued navigation property opportunity_customer_accounts."
for contacts i can guess it's contact_customer_accounts and contact_customer_contacts maybe?
this will hopefully create everything at once, but how to associate to the connection is a another problem.
without testing, something like this could work:
{
"record1roleid@odata.bind":"/connectionroles(1EB54AB1-58B7-4D14-BF39-4F3E402616E8)",
"record2roleid@odata.bind":"/connectionroles(35A23B91-EC62-41EA-B5E5-C59B689FF0B4)",
"record1id_contact": {
"contact_customer_contacts":
[
{
"firstname": "asd",
"lastname": "asd"
}
]
},
"record2id_account": {
"contact_customer_accounts":
[
{
"name": "SOLE TRADER",
"emailaddress1":"otbpostman1@post.com",
"telephone1":"07188888"
}
]
}
}
来源:https://stackoverflow.com/questions/54790306/why-is-deep-insert-failing-when-trying-to-create-a-contact-and-account-entities