web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to use something like following:

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

  • Sompop Profile Picture
    25 on at

    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.

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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
    25 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans