尝试通过Dynamics WebAPI中的连接创建联系人和客户实体时,为什么深层插入失败 [英] Why is deep insert failing when trying to create a Contact and Account entities through a Connection in Dynamics WebAPI

查看:108
本文介绍了尝试通过Dynamics WebAPI中的连接创建联系人和客户实体时,为什么深层插入失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够使用类似于以下内容的有效载荷在Dynamics WebAPI中创建联系人...

{ 
     "firstname": "asd",
     "lastname": "asd"
}

我已经能够使用类似于以下内容的有效负载在Dynamics WebAPI中创建一个Account实体...

{
    "name":"SOLE TRADER ORG",
    "emailaddress1":"otbpostman1@post.com",
    "telephone1":"07188888"
}

以及两者之间的Connection实体,如下所示...

{
    "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)"
}

根据此页面我应该能够进行深度插入,在其中我可以在一个请求中自动创建所有三个对象,我已经尝试了以下方法...

{
    "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"
    }
}

...周围还有很多变化,但是没有运气.我不断收到类型错误...

代码":"0x80048210", "message":正在连接的两个对象均丢失."

我是否错过了一些关键功能,这意味着这是不可能的?

解决方案

我认为record2id_account期望使用GUID,这样就行不通了,

正如您所链接的页面所说,他们是偶然地这样做的,他们会使用

创建了机会,因为机会被定义为设置为 集合值的导航属性机会_customer_accounts 的值的数组中的对象." >

对于联系人,我猜可能是 contact_customer_accounts contact_customer_contacts ?

这有望一次创建所有内容,但是如何关联到连接是另一个问题.

未经测试,类似的方法可能会起作用:

{
"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"
   }
   ]
}
}

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?

解决方案

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"
   }
   ]
}
}

这篇关于尝试通过Dynamics WebAPI中的连接创建联系人和客户实体时,为什么深层插入失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆