Hi experts,
i have this question i'm tryingto set a record on dynamics 365 via web api using a console application on c# string data Works like a charm, but i need to insert data on a lookup field that is related to the lead entity and i don't know what the heck i should do :D...
Here the scenario, i call some variables, one of them its queried to CRM via web Api to return his GUID, when i receive the GUID i have to set it on the lookup field, but didn't know how to insert it... always get a brake on that action or the record is created without that data...
Here the code that i'm trying to run.
string LeadName = "Ville 2"; string LeadLastName = "Web Api Lead 2"; string LeadEmail = "3webapi@lead1.com"; string LeadTopic = "WebApi Lead 3"; string LeadSource = "Contact Us"; string queryLeadSource; queryLeadSource = "new_leadsources?$select=new_leadsourceid&$filter=new_name eq '" + LeadSource + "'"; HttpResponseMessage responsePost = await client.PostAsJsonAsync(queryLeadSource, true); string leadSourceId = null; if (responsePost.StatusCode == HttpStatusCode.OK){ JObject lsRetreived = JsonConvert.DeserializeObject<JObject>(await responsePost.Content.ReadAsStringAsync()); leadSourceId = lsRetreived["new_leadsourceid"].ToString(); } else{ Console.WriteLine("Error retrieving lead source ID!"); throw new CrmHttpResponseException(responsePost.Content); } JObject newLead = new JObject(); newLead.Add("firstname", LeadName); newLead.Add("lastname", LeadLastName); newLead.Add("emailaddress1", LeadEmail); newLead.Add("subject", LeadTopic); newLead.Add("new_leadsource@odata.bind", "/new_leadsources("+ leadSourceId +")"); HttpResponseMessage response = await client.PostAsJsonAsync("leads", newLead);
*This post is locked for comments