使用 WebAPI 设置 CRM 查找值
Set CRM Lookup Values with WebAPI
谁完成了 CRM Web API 调用以使用来自另一个实体的查找值更新 CRM 实体。
我正在尝试使用 WebAPI、CRM 2016 为 CRM 中的另一个实体设置查找值。如果我禁用查找值,它会起作用,但一旦启用查找值,我就会收到错误请求.
下面是我在 LinqPad 中的代码,所以它确实有效。
void Main()
{
using(var webClient = new WebClient()){
webClient.Credentials = new NetworkCredential("Username", "Password", "Domain");
webClient.Headers.Add("OData-MaxVersion", "4.0");
webClient.Headers.Add("OData-Version", "4.0");
webClient.Headers.Add("accept", "application/json");
webClient.Headers.Add("Content-Type","application/json");
webClient.Headers.Add("Prefer", "odata.include-annotations=*");
webClient.BaseAddress = "http://dev.company.com/DEV2016/api/data/v8.0/";
var JO = new JObject();
JO.Add("col_name","My Name");
//JO.Add("col_contactid@odata.bind","/contacts(7266f26b-7105-e611-811e-005056b61789)");
var dataString = JO.ToString();
var responseString = webClient.UploadString("col_advisors", "POST", dataString);
Console.WriteLine(webClient.ResponseHeaders.Get("OData-EntityId"));
}
}
WebAPI 的大小写很重要。确保您的 col_contactid 是架构名称,而不是逻辑名称。例如,您的属性的逻辑名称是 col_contactid(逻辑名称总是小写),但模式名称通常有大写字母。例如,你的可能是 col_ContactId,在这种情况下你会想要使用 col_ContactId@odata.bind
.
查找属性的架构名称的最简单方法是转至 CRM -> 设置 -> 解决方案 -> 您的解决方案 -> 实体(在左侧)-> 顾问 -> 字段。在该网格中,您将看到模式名称列。
我让它工作了。这些字段确实必须是唯一的,因为它区分大小写。在这里和这个博客发表评论,真的很有帮助。
http://inogic.com/blog/2016/02/set-values-of-all-data-types-using-web-api-in-dynamics-crm/
Step 1 : Goto Cutomization Developer Resource.
Step 2 : Click to “Download Odata Metadata” link and Download the same.
Step 3 : Once Download, open it and find out name of lookup attribute ( i.e. new_qualifiedleadid
) and check its casing.
Step 4 : Verify it with the value which you are setting in the code it should be same.
虽然我的专栏是 col_contactid
,但 CRM 将导航栏重命名为 col_ContactId
上方的内容。
我还使用了 Postman(google chrome) 插件并将以下 Header 添加到我的 Post.
webClient.Headers.Add("Prefer", "odata.include-annotations=*");
谁完成了 CRM Web API 调用以使用来自另一个实体的查找值更新 CRM 实体。
我正在尝试使用 WebAPI、CRM 2016 为 CRM 中的另一个实体设置查找值。如果我禁用查找值,它会起作用,但一旦启用查找值,我就会收到错误请求.
下面是我在 LinqPad 中的代码,所以它确实有效。
void Main()
{
using(var webClient = new WebClient()){
webClient.Credentials = new NetworkCredential("Username", "Password", "Domain");
webClient.Headers.Add("OData-MaxVersion", "4.0");
webClient.Headers.Add("OData-Version", "4.0");
webClient.Headers.Add("accept", "application/json");
webClient.Headers.Add("Content-Type","application/json");
webClient.Headers.Add("Prefer", "odata.include-annotations=*");
webClient.BaseAddress = "http://dev.company.com/DEV2016/api/data/v8.0/";
var JO = new JObject();
JO.Add("col_name","My Name");
//JO.Add("col_contactid@odata.bind","/contacts(7266f26b-7105-e611-811e-005056b61789)");
var dataString = JO.ToString();
var responseString = webClient.UploadString("col_advisors", "POST", dataString);
Console.WriteLine(webClient.ResponseHeaders.Get("OData-EntityId"));
}
}
WebAPI 的大小写很重要。确保您的 col_contactid 是架构名称,而不是逻辑名称。例如,您的属性的逻辑名称是 col_contactid(逻辑名称总是小写),但模式名称通常有大写字母。例如,你的可能是 col_ContactId,在这种情况下你会想要使用 col_ContactId@odata.bind
.
查找属性的架构名称的最简单方法是转至 CRM -> 设置 -> 解决方案 -> 您的解决方案 -> 实体(在左侧)-> 顾问 -> 字段。在该网格中,您将看到模式名称列。
我让它工作了。这些字段确实必须是唯一的,因为它区分大小写。在这里和这个博客发表评论,真的很有帮助。
http://inogic.com/blog/2016/02/set-values-of-all-data-types-using-web-api-in-dynamics-crm/
Step 1 : Goto Cutomization Developer Resource.
Step 2 : Click to “Download Odata Metadata” link and Download the same.
Step 3 : Once Download, open it and find out name of lookup attribute ( i.e.
new_qualifiedleadid
) and check its casing.Step 4 : Verify it with the value which you are setting in the code it should be same.
虽然我的专栏是 col_contactid
,但 CRM 将导航栏重命名为 col_ContactId
上方的内容。
我还使用了 Postman(google chrome) 插件并将以下 Header 添加到我的 Post.
webClient.Headers.Add("Prefer", "odata.include-annotations=*");