【问题标题】:How do I set the value of an OptionSet in Dynamics 365 CRM API in ASP.NET Core?如何在 ASP.NET Core 的 Dynamics 365 CRM API 中设置 OptionSet 的值?
【发布时间】:2022-01-24 03:17:01
【问题描述】:

我正在尝试更新作为选项集的现有 Dynamics 365 帐户属性。我使用 value: intId 创建了一个字典,其中 intId 是该特定属性值的 Dynamics 365 的 ID。

下面的代码适用于多选选项,您可以将所有数字 id 连接起来,用逗号分隔,但是当我尝试使用选项集时,它会显示

提供的属性是 System.String 类型,而预期是 System.Int32 类型

var config = new ServiceConfig(ConnectionString);

using (var service = new CDSWebApiService(config))
{
    string url = $"{BaseUrl}accounts({dynGuid})";
    //var jContent = (JObject)JToken.FromObject(accountType);
    //.put accepts the url, attribute to change, and the value to apply
    service.Put(url, "customertypecode", customerTypeCode);
}

发送的customerTypeCode 是“#########”,它是 D365 中相应的 9 位 ID。我是否需要为期望整数值(如customertypecode)的属性重载 put 方法?

上述方法与用于设置多选属性的方法几乎相同,其中为第三个参数传递的值是 D365 中属性值的串联 int Id 字符串。我不确定为什么它现在抛出除了选项集之外的错误必须与多选属性不同。

除了如何在 D365 中向选项集插入更多值之外,我似乎找不到关于选项集的文档,但我知道我遗漏了一些明显的东西。

【问题讨论】:

  • 感谢@marc_s 的编辑,并对格式不正确的问题表示歉意。

标签: c# asp.net-core dynamics-crm dynamics-365


【解决方案1】:

看起来像将主体创建为对象并使用 Patch 而不是 Put 发送请求就可以了。它只需要代表主体的 Uri 和 JObject 并相应地更新记录。

var accountType = new
                  {
                     customertypecode = customerTypeString
                  };

string url = $"{BaseUrl}accounts({dynGuid})";
Uri updateUrl = new Uri(url);

var jContent = (JObject)JToken.FromObject(accountType);

service.Patch(updateUrl, jContent);

【讨论】:

    猜你喜欢
    • 2011-11-11
    • 2017-01-18
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 2019-08-12
    相关资源
    最近更新 更多