Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics 365 Web API Create a Contact Record with Customer Type field

Posted on by 25

Hi there,

When I create a contact JObject without a customer type field, it works fine. However, when I tried with the "ParentCustomerId" field, it does not work. I looked it up and found out that this field is not a lookup field, but the Customer type field. I could not find anyone talking about this. Any advice/suggestion would be appreciated.

JObject contactAlt = new JObject();

contactAlt.Add("contactid", Guid.Parse(contactGuid));

//contactAlt["parentcustomerid@odata.bind"] = "/accounts(A7CFD688-8DF7-E611-8109-E0071B6AB1A1)";
//contactAlt.Add("parentcustomerid@odata.bind", "/accounts(A7CFD688-8DF7-E611-8109-E0071B6AB1A1)");
contactAlt.Add("firstname", firstName);
contactAlt.Add("lastname", lastName);
contactAlt.Add("jobtitle", title);
contactAlt.Add("address1_line1", address1);
contactAlt.Add("address1_line2", address2);
contactAlt.Add("address1_city", city);
contactAlt.Add("address1_stateorprovince", stateOrProvince);
contactAlt.Add("address1_postalcode", postalCode);
contactAlt.Add("address1_country", country);
contactAlt.Add("address1_telephone1", businessPhone);
contactAlt.Add("emailaddress1", email);

string queryOptions = "?$select=fullname,annualincome,jobtitle,contactid";
HttpRequestMessage createRequestAlt =
new HttpRequestMessage(HttpMethod.Post, getVersionedWebAPIPath() + "contacts" + queryOptions);
createRequestAlt.Content = new StringContent(contactAlt.ToString(),
Encoding.UTF8, "application/json");
createRequestAlt.Headers.Add("Prefer", "return=representation");

HttpResponseMessage createResponseAlt = await httpClient.SendAsync(createRequestAlt);
if (createResponseAlt.StatusCode == HttpStatusCode.Created) //201
{
//Body should contain the requested new-contact information.
JObject createdContactAlt = JsonConvert.DeserializeObject<JObject>(
await createResponseAlt.Content.ReadAsStringAsync());
//Because 'OData-EntityId' header not returned in a 201 response, you must instead
// construct the URI.
contactAltUri = httpClient.BaseAddress + getVersionedWebAPIPath() + "contacts(" + createdContactAlt["contactid"] + ")";

}

Regards,

Sompop

*This post is locked for comments

  • Sompop Profile Picture
    Sompop 25 on at
    RE: Dynamics 365 Web API Create a Contact Record with Customer Type field

    I actually read the same article as you ... Thanks for enlightening me :)

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dynamics 365 Web API Create a Contact Record with Customer Type field

    You should check this - https://msdn.microsoft.com/en-us/library/mt607990.aspx#bkmk_properties

    Here is a quote:

    Lookup properties

    For most single-valued navigation properties you will find a computed, read-only property that uses the following naming convention: _<name>_value where the <name> matches the name of the single-valued navigation property. The exception to this pattern is when a lookup attribute of the entity can accept multiple types of entity references. A common example is how the incident entity customerid attribute may be set to a reference that is either a contact or account entity. In the incident EntityTypeSingle-valued navigation properties you will find customerid_account and customerid_contact as separate single-valued navigation properties to reflect the customer associated with an opportunity. If you set one of these single-valued navigation properties, the other will be set to null because they are both bound to the customerid attribute. In the incident EntityTypeProperties you’ll find a _customerid_value lookup property that contains the same value that is set for whichever of the single-valued navigation properties contain a value.

  • Sompop Profile Picture
    Sompop 25 on at
    RE: Dynamics 365 Web API Create a Contact Record with Customer Type field

    Hi Andrii,

    I would like to personally thank you for your fast response. I also found out from Jason and tested that it worked.

    community.dynamics.com/.../609922

    One more question. Where is Microsoft documentation that talks about this particular case so I can learn from it.

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Dynamics 365 Web API Create a Contact Record with Customer Type field

    Hello,

    Try to use something like following:

    contactAlt["parentcustomerid_account@odata.bind"] = "/accounts(A7CFD688-8DF7-E611-8109-E0071B6AB1A1)";

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans