【问题标题】:Dynamics CRM 365 - update fields using any unique field except GUID fieldDynamics CRM 365 - 使用除 GUID 字段之外的任何唯一字段更新字段
【发布时间】:2017-12-15 05:50:59
【问题描述】:

我想使用PATCH / PUT 使用HttpClient 更新Contact 实体的firstname 字段。

我已经尝试使用PATCH 和联系人的GUID。但是,如果我尝试使用以下 URL:

baseURL/contacts(myorg_contactnumber='113')

baseURL/contacts('113')

baseURL/contacts(myorg_contactnumber="113")

但它正在抛出 Bad Request 错误。

【问题讨论】:

  • 您需要在联系人实体上设置备用键才能使用,并使用该键名来引用联系人记录。
  • 请提供发出此请求的代码。

标签: c# httprequest dynamics-crm dotnet-httpclient dynamics-crm-webapi


【解决方案1】:

没有看到你的代码,就像 Jatin 说的那样 - 可能只有错过的可能是Alternate key setup

这样的 PATCH 请求的好处是,默认情况下,如果存在,它将更新 record,如果不存在,它将创建 record'不存在。

url: /api/data/v8.2/contacts(new_alternatekey='12345')
method: PATCH
body: {
    "name": "Alternate key contact updated"
}

你也标记了 C#,所以试试this

   JObject contact1Add = new JObject();
   contact1Add.Add("firstname", "Jack");

   HttpRequestMessage updateRequest1 = new HttpRequestMessage(
       new HttpMethod("PATCH"), contact1Uri);
   updateRequest1.Content = new StringContent(contact1Add.ToString(),
       Encoding.UTF8, "application/json");
   HttpResponseMessage updateResponse1 =
       await httpClient.SendAsync(updateRequest1);
   if (updateResponse1.StatusCode == HttpStatusCode.NoContent) //204
   {
    Console.WriteLine("Contact '{0} {1}' updated with " +
        "firstname", contact1.GetValue("firstname"),
        contact1.GetValue("lastname"));
   }
   else
   {
    Console.WriteLine("Failed to update contact for reason: {0}",
        updateResponse1.ReasonPhrase);
    throw new CrmHttpResponseException(updateResponse1.Content);
   }

【讨论】:

    猜你喜欢
    • 2016-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    相关资源
    最近更新 更多