本文介绍了使用Web API在CRM数据库中添加查找GUID字段时出现错误的请求错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CRM的自定义实体中插入一条新记录,其中的一个字段为查找类型,即new_contactid,它依赖于contact实体.

I want to insert a new record in CRM's custom entity where one of the fields is of lookup type i.e. new_contactid and it is dependent on the contact entity.

我也提到了在Dynamics CRM中通过C#使用Web API设置所有数据类型的值.

我的 JSON 数据如下:

{ "new_transactionnumber":"114", "new_transactionamount":650, "new_transactiondate":"2018-01-29T15:01:00.000Z", "[email protected]":"/contacts(afb9e006-6be5-e711-80ed-bef806786223)", "[email protected]":"/new_moves(896f2dcd-b2fa-e711-80ef-bef806786223)"}

{ "new_transactionnumber":"114", "new_transactionamount":650, "new_transactiondate":"2018-01-29T15:01:00.000Z", "[email protected]":"/contacts(afb9e006-6be5-e711-80ed-bef806786223)", "[email protected]":"/new_moves(896f2dcd-b2fa-e711-80ef-bef806786223)"}

在这里,最后2个字段用于查找GUID.原始字段名称为:

Here, last 2 fields are for lookup GUID. Original field names are:

  • new_contactid
  • new_moveid

我最后添加的是主键的实体名称.

如果我在这里遗漏任何东西,请告诉我.

Please let me know if I am missing anything in here.

编辑1 :以下是我在OData文件中找到的查找字段的引用:

EDIT 1:Below is the references I found in OData file for lookup field:

<NavigationProperty Name="new_contact_new_transaction_contactid" Type="Collection(mscrm.new_transaction)" Partner="new_contactid" />

<Property Name="_new_contactid_value" Type="Edm.Guid">
  <Annotation Term="Org.OData.Core.V1.Description" String="ContactId" />
  <Annotation Term="Org.OData.Core.V1.Computed" Bool="true" />
  <Annotation Term="Org.OData.Core.V1.Permissions">
    <EnumMember>Org.OData.Core.V1.PermissionType/Read</EnumMember>
  </Annotation>
</Property>

<NavigationProperty Name="new_contactid" Type="mscrm.contact" Nullable="false" Partner="new_contact_new_transaction_contactid">
  <ReferentialConstraint Property="_new_contactid_value" ReferencedProperty="contactid" />
</NavigationProperty>

<NavigationPropertyBinding Path="new_contact_new_transaction_contactid" Target="new_transactions" />

<NavigationPropertyBinding Path="new_contactid" Target="contacts" />

编辑2 :这些查找字段是GUID绑定到其他现有实体的主键.

推荐答案

基本上,导航属性将使用架构名称(驼峰式大写)而不是逻辑名称(帕斯卡大写).

Basically the Navigation property will use the Schema Name (Camel casing) not the Logical name (pascal casing).

请参考此博客文章评论部分&适当更改:

Please refer the comment in this blog post comments section & change appropriately:

第1步:转到个性化"开发人员资源".

Step 1 : Goto Cutomization  Developer Resource.

第2步:点击下载Odata元数据"链接,然后下载 一样.

Step 2 : Click to "Download Odata Metadata" link and Download the same.

第3步:下载后,将其打开并找出查阅属性的名称 (即"new_qualifiedleadid")并检查其大小写.

Step 3 : Once Download, open it and find out name of lookup attribute ( i.e. "new_qualifiedleadid") and check its casing.

第4步:使用您在代码中设置的值验证它 应该是相同的.

Step 4 : Verify it with the value which you are setting in the code it should be same.

这篇关于使用Web API在CRM数据库中添加查找GUID字段时出现错误的请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:41