问题
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.
I have also referred Set Values of all Data Types using Web API in Dynamics CRM Through C#.
My JSON data is as below:
{
"new_transactionnumber":"114",
"new_transactionamount":650,
"new_transactiondate":"2018-01-29T15:01:00.000Z",
"new_contactid_contact@odata.bind":"/contacts(afb9e006-6be5-e711-80ed-bef806786223)",
"new_moveid_new_move@odata.bind":"/new_moves(896f2dcd-b2fa-e711-80ef-bef806786223)"
}
Here, last 2 fields are for lookup GUID. Original field names are:
- new_contactid
- new_moveid
What I have added to the end is it's primary key's entity name.
Please let me know if I am missing anything in here.
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" />
EDIT 2: These lookup fields are GUID bound to other existing entity's primary key.
回答1:
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:
Please follow the steps listed below :
Step 1 : Goto Cutomization Developer Resource.
Step 2 : Click to “Download Odata Metadata” link and Download the same.
Step 3 : Once Download, open it and find out name of lookup attribute ( i.e. “new_qualifiedleadid”) and check its casing.
Step 4 : Verify it with the value which you are setting in the code it should be same.
来源:https://stackoverflow.com/questions/48502747/bad-request-error-while-adding-a-lookup-guid-field-in-crm-database-using-web-api