You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Dynamics 365 Sales:增强体验添加产品至单据能否自定义移除productdescription?

Dynamics 365 Sales 产品添加至单据时移除productdescription属性的配置方案

我使用的是Dynamics 365 Sales企业版(版本9.0.22121.10002),通过增强体验将产品添加至报价、商机、发票等单据时,系统会通过Web API批量发送创建记录请求,其中一条请求载荷如下:

POST /api/data/v9.0/quotedetails HTTP/1.1

{
    "ispriceoverridden": false,
    "ofml_lineno": 1,
    "ofml_section": 1,
    "priceperunit": 2105.26,
    "productdescription": "Testing - prod description",
    "productid@odata.bind": "/products(848ecbf6-5878-ec11-8d21-000d3ad55516)",
    "quantity": 1,
    "quoteid@odata.bind": "/quotes(d07f272c-70b3-ed11-b596-6045bdd2b5e7)",
    "uomid@odata.bind": "/uoms(baae8a55-cb0b-ec11-b6e6-002248422a3d)"
}

目前存在两种请求失败场景:

  • 当产品已设置长度小于500字符的描述时,报错:You cannot set both 'productid' and 'productdescription' for the same record.
  • 当产品描述长度超过500字符时,报错:The length of the 'productdescription' attribute of the 'opportunityproduct' entity exceeded the maximum allowed length of '500'.

只有产品描述为空时,请求才能正常执行。咨询是否可以通过自定义配置,在从Product向QuoteProduct等实体转移数据时移除productdescription属性?


可以通过以下几种自定义配置方式实现需求:

1. 注册预操作插件拦截请求

创建**预操作(Pre-operation)**插件,注册在quotedetail、opportunityproduct、invoicedetail等目标实体的Create消息上。在插件逻辑中直接移除请求载荷里的productdescription字段。

核心代码片段:

public void Execute(IServiceProvider serviceProvider)
{
    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity target)
    {
        if (target.Contains("productdescription"))
        {
            target.Attributes.Remove("productdescription");
        }
    }
}

2. 修改增强体验的前端脚本

如果增强体验的产品添加功能基于可自定义的Web资源或页面,找到触发Web API请求的JavaScript代码,在构建请求载荷时直接移除productdescription字段。

示例代码片段:

function buildLineItemPayload(product, parentId, entityName) {
    let payload = {
        "ispriceoverridden": false,
        "ofml_lineno": 1,
        "ofml_section": 1,
        "priceperunit": product.priceperunit,
        "productid@odata.bind": `/products(${product.id})`,
        "quantity": 1,
        [`${entityName}id@odata.bind`]: `/${entityName}s(${parentId})`,
        "uomid@odata.bind": `/uoms(${product.uomid})`
        // 移除productdescription字段,不再传入
    };
    return payload;
}

3. 业务规则补充(仅作辅助)

在quotedetail等实体上创建业务规则:当productid被赋值时,自动清空productdescription字段。但这种方式是记录创建后触发,无法完全避免初始Web API报错,仅作为兜底方案。

注意事项

  • 插件需覆盖所有相关实体的Create操作,确保批量添加场景下所有请求都被处理。
  • 测试时需验证单条和批量添加产品的场景,确保功能正常且无报错。

内容的提问来源于stack exchange,提问作者lazarus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 08:42:46