Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

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

$
0
0

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


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images