1

我有一个与 crm 货币字段(estimatedrevenue)有关的问题,这是自定义字段和小数字段(RevenueIncludingTax)。我计算货币基值 = Math.ceil(RevenueIncludingTax)。当我尝试使用 Javascript 时,有时是正确的,有时是错误的。所以我尝试编写插件,并更新基值。虽然插件正在工作并在编码中更新值,但是当打开表单时它会显示错误消息并且不会更新基值。我怀疑我可以更新货币基础价值吗?

这是我的插件代码,

public class EstimatedRevenue : IPlugin
{
    #region Class Level Variables
    //IServiceProvider _serviceProvider;
    //IOrganizationServiceFactory _serviceFactory = null;
    //IOrganizationService _service = null;
    //IPluginExecutionContext _context = null;

    Entity _target = null;
    Entity _preImage = null;
    Entity _postImage = null;
    Guid _currentUser;
    decimal revinvtax;
    #endregion

    #region  IPlugin Members
    public void Execute(IServiceProvider serviceProvider)
    {
        try
        {
            string message = null;
            IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            #region Organization Services
            // Obtain the organization service reference.
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(_context.UserId);
            #endregion

            var ServiceContext = new OrganizationServiceContext(service);

            _currentUser = _context.UserId;
            message = _context.MessageName.ToLower();

            if (message == "create") 
            {
                if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
                    _target = (Entity)_context.InputParameters["Target"];

                if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
                    _preImage = (Entity)_context.PreEntityImages["PreImage"];

                if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
                    _postImage = (Entity)_context.PostEntityImages["PostImage"];

                if (_target.Attributes.Contains("hm_revenueincludingtax"))
                {
                    revinvtax = (decimal)_target.Attributes["hm_revenueincludingtax"];
                    decimal ceilvalue = Math.Ceiling(revinvtax);
                    _target.Attributes["hm_estimatedrevenue_base"] = ceilvalue;
                    service.Update(_target);
                }
            }
            if (message == "update")
            {
                if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] != null)
                    _target = (Entity)_context.InputParameters["Target"];

                if (_context.PreEntityImages.Contains("PreImage") && _context.PreEntityImages["PreImage"] != null)
                    _preImage = (Entity)_context.PreEntityImages["PreImage"];

                if (_context.PostEntityImages.Contains("PostImage") && _context.PostEntityImages["PostImage"] != null)
                    _postImage = (Entity)_context.PostEntityImages["PostImage"];

                if (_target.Attributes.Contains("hm_revenueincludingtax"))
                {
                    revinvtax = (decimal)_target.Attributes["hm_revenueincludingtax"];
                    decimal ceilvalue = Math.Ceiling(revinvtax);
                    _target.Attributes["hm_estimatedrevenue_base"] = ceilvalue;
                    //service.Update(_target);
                    //ServiceContext.AddObject(_target);
                    //ServiceContext.SaveChanges();
                }
            }
        }
        catch (Exception ex)
        {
            throw new InvalidPluginExecutionException(ex.Message, ex);
        }
    }
    #endregion
}

这是我打开表单时的错误页面, 在此处输入图像描述

4

2 回答 2

2

不要更新_base属性 - 它的内部。而是更新您创建的属性 ( hm_estimatedrevenue)。它将采用调用用户的货币,并_base会自动处理。

于 2012-06-20T06:30:17.840 回答
0

_base顾名思义,它存储在基础货币值中。因此,如果您在欧洲并在安装过程中将基础货币设置为欧元,那么它在_base. 如果输入 250 欧元,_base将有 250 的值。

hm_estimatedrevenue字段计算:_bases/exchange_rate以适应多币种组织。

但是,您必须更新hm_estimatedrevenue,因为_base它是一个readonly字段。

希望这可以帮助。

于 2013-04-02T16:16:59.357 回答