首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CRM 2013更新Quote Product部分

CRM 2013更新Quote Product部分
EN

Stack Overflow用户
提问于 2014-11-27 13:58:32
回答 1查看 1.2K关注 0票数 0

是否有人试图创建一个插件来更新中记录的值?我创建了一个,因为我需要一个自定义公式来计算Extended字段,但是在CRM中有一些自动计算来填充这些字段。这根本不允许我更新计算公式。

我的插件做的是:

  1. 获取单位价格、数量和折扣%字段中的值(这是一个自定义字段);
  2. 计算我需要的价值;
  3. 将其设置为extended字段。

但是,所有这些都不起作用,因为我得到了一个“业务流程错误”;基本上,这个错误告诉我,我不能使用记录的guid来访问它。

这是我的代码:

代码语言:javascript
复制
protected void ExecutePostQuoteProductUpdate(LocalPluginContext localContext)
    {
        if (localContext == null)
        {
            throw new ArgumentNullException("localContext");
        }

        IPluginExecutionContext context = localContext.PluginExecutionContext;
        IOrganizationService service = localContext.OrganizationService;

        Guid quoteProductID = (Guid)((Entity)context.InputParameters["Target"]).Id;
        ColumnSet set = new ColumnSet();
        set.AllColumns = true;

        var quote = service.Retrieve("quotedetail", quoteProductID, set);
        var priceperunit = quote.Attributes["priceperunit"];
        var teamleader = quote.Attributes["new_disc"];
        var manualdiscountamount = quote.Attributes["manualdiscountamount"];
        var volumediscountamount = quote.Attributes["volumediscountamount"];
        var VAT = (int)quote.Attributes["new_vat"];

        var discountamount = (double)priceperunit * (double)teamleader / 100;
        var baseamount = (double)priceperunit - discountamount;
        var tax = baseamount * VAT / 100;
        var extendedamount = baseamount + tax;
        quote.Attributes["new_discountamount"] = discountamount;
        quote.Attributes["baseamount"] = baseamount;
        quote.Attributes["tax"] = tax;
        quote["description"] = priceperunit;
        quote.Attributes["extendedamount"] = extendedamount;
        service.Update(quote);


    }

请告诉我是否有方法访问这些字段并使用/设置它们。

提前谢谢!/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-30 14:11:38

您不能直接更新extendedamount,相反,如果您使用自动计算它的内置字段,那么CRM将为您处理这个问题。

这些字段是:baseamountquantitydiscountamounttax。这些是Money字段,因此您需要将它们存储为这样:

代码语言:javascript
复制
quote.Attributes["baseamount"] = new Money(baseamount); // Money and decimal numbers use the "decimal" datatype and not double.

至于您的自定义计算,您只需要将自定义字段中存储的百分比转换为实际金额,并将其分配给discountamount属性。类似于:

代码语言:javascript
复制
var discountamount = (decimal)priceperunit * (decimal)teamleader / 100;
// Assigning the actual discount amount will automatically recalculate the extended amount on the line.
// No need to recalculate all fields. 
quote.Attributes["discountamount"] = new Money(discountamount);

请注意,tax可能需要重新计算以反映折扣,但流程应该完全相同。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27172400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档