D365插件错误来自ISV代码出乎意料的错误
您好,世界上的编码器,
我正在编写我的第一个D365插件,并且遇到了一个问题。当我保存表格时,什么也不会发生。
我在报价产品实体上注册了用于计算“增值税金额”的插件(更新消息,后操作)。我有一个相关的“增值税”实体,其中包含一个整数。该插件检索该整数并变成十进制(代表一个百分比)。增值税的数量是通过将该小数乘以引用产品中的数量来计算的:
decimal amountVatExcluded = baseAmount - discount;
decimal vatAmount = amountVatExcluded * vatPercentage;
decimal amountVatIncluded = amountVatExcluded + vatAmount;
当我调试插件时,在第41行中丢弃了错误,
decimal vatPercentage = GetVatPercentage(quoteLine, service);
该错误通过从方法getVarperCentage中撤回小数来声明变量:
private decimal GetVatPercentage(Entity quoteLine, IOrganizationService service)
{
Guid vatId = (Guid)quoteLine.Attributes["capdcx_valueaddedtax"];
ColumnSet attributesVatEntity = new ColumnSet("capdcx_valueaddedtaxpercentage");
Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", vatId, attributesVatEntity);
decimal vatPercentageAsWholeNumber = 0;
if (vatEntity.Attributes.Contains("capdcx_valueaddedtaxpercentage"))
{
vatPercentageAsWholeNumber = (decimal)vatEntity.Attributes["capdcx_valueaddedtaxpercentage"];
}
decimal vatPercentage = vatPercentageAsWholeNumber / 100;
return vatPercentage;
}
我无法对vatpercentage十进制的检索错误。有什么想法吗? Bewlow是完整的代码:
public void Execute(IServiceProvider serviceProvider)
{
#region pluginbase
ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
#endregion
#region attributes
tracing.Trace("Obtaining Target (quoteLine) entity and attributes");
Entity quoteLine = (Entity)context.InputParameters["Target"];
ColumnSet attributesQuoteline = new ColumnSet(new string[]
{
"baseamount",
"manualdiscountamount",
"capdcx_valueaddedtax"
});
service.Retrieve("quotedetail", quoteLine.Id, attributesQuoteline);
#endregion
//access related VAT entity, get its integer and turn it into decimal for percentage
decimal vatPercentage = GetVatPercentage(quoteLine, service);
//define price, discount, and final price without VAT
decimal baseAmount = 0;
if (quoteLine.Attributes.Contains("baseamount"))
{
baseAmount = (decimal)quoteLine.Attributes["baseamount"];
}
decimal discount = 0;
if (quoteLine.Attributes.Contains("manualdiscountamount"))
{
discount = (decimal)quoteLine.Attributes["manualdiscountamount"];
}
decimal amountVatExcluded = baseAmount - discount;
decimal vatAmount = amountVatExcluded * vatPercentage;
decimal amountVatIncluded = amountVatExcluded + vatAmount;
var quotelineUpdated = new Entity(quoteLine.LogicalName, quoteLine.Id);
quotelineUpdated.Attributes["capdcx_valueaddedtaxexcluded"] = new Money(amountVatExcluded);
quotelineUpdated.Attributes["capdcx_valueaddedtax"] = new Money(vatAmount);
quotelineUpdated.Attributes["extendedamount"] = new Money(amountVatIncluded);
service.Update(quotelineUpdated);
tracing.Trace("Succesfully set amounts of quoteLine");
// onCreate en onSave
}
private decimal GetVatPercentage(Entity quoteLine, IOrganizationService service)
{
Guid vatId = (Guid)quoteLine["capdcx_valueaddedtax"];
ColumnSet attributesVatEntity = new ColumnSet(new string[]
{
"capdcx_valueaddedtaxpercentage"
});
Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", vatId, attributesVatEntity);
//Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", (Guid)quoteLine["capdcx_valueaddedtax"], new ColumnSet("capdcx_valueaddedtaxpercentage"));
decimal vatPercentageAsWholeNumber = 0;
if (vatEntity.Attributes.Contains("capdcx_valueaddedtaxpercentage"))
{
vatPercentageAsWholeNumber = (decimal)vatEntity.Attributes["capdcx_valueaddedtaxpercentage"];
}
decimal vatPercentage = vatPercentageAsWholeNumber / 100;
return vatPercentage;
}
非常感谢!
问候, Malliendk
Hello coders of the world,
I'm writing my first d365 plugin and I'm encountering a problem. When I save my form, nothing happens.
I'm registered the plugin on the Quote Product entity for calculating "VAT amount" (Update message, Post Operation). I have a related "VAT" entity, which contains an integer. The plugin retrieves this integer and turns into a decimal (which represents a percentage). The VAT amount is calculated by multiplying this decimal by the amount in Quote Product:
decimal amountVatExcluded = baseAmount - discount;
decimal vatAmount = amountVatExcluded * vatPercentage;
decimal amountVatIncluded = amountVatExcluded + vatAmount;
When I debug the plugin, an error is thrown at line 41,
decimal vatPercentage = GetVatPercentage(quoteLine, service);
which declares a variable by retrtieving a decimal from a method GetVarPercentage:
private decimal GetVatPercentage(Entity quoteLine, IOrganizationService service)
{
Guid vatId = (Guid)quoteLine.Attributes["capdcx_valueaddedtax"];
ColumnSet attributesVatEntity = new ColumnSet("capdcx_valueaddedtaxpercentage");
Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", vatId, attributesVatEntity);
decimal vatPercentageAsWholeNumber = 0;
if (vatEntity.Attributes.Contains("capdcx_valueaddedtaxpercentage"))
{
vatPercentageAsWholeNumber = (decimal)vatEntity.Attributes["capdcx_valueaddedtaxpercentage"];
}
decimal vatPercentage = vatPercentageAsWholeNumber / 100;
return vatPercentage;
}
I can't fingure out what's wrong with this retrieval of the VatPercentage decimal. Any thoughts? Bewlow is the full code:
public void Execute(IServiceProvider serviceProvider)
{
#region pluginbase
ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
#endregion
#region attributes
tracing.Trace("Obtaining Target (quoteLine) entity and attributes");
Entity quoteLine = (Entity)context.InputParameters["Target"];
ColumnSet attributesQuoteline = new ColumnSet(new string[]
{
"baseamount",
"manualdiscountamount",
"capdcx_valueaddedtax"
});
service.Retrieve("quotedetail", quoteLine.Id, attributesQuoteline);
#endregion
//access related VAT entity, get its integer and turn it into decimal for percentage
decimal vatPercentage = GetVatPercentage(quoteLine, service);
//define price, discount, and final price without VAT
decimal baseAmount = 0;
if (quoteLine.Attributes.Contains("baseamount"))
{
baseAmount = (decimal)quoteLine.Attributes["baseamount"];
}
decimal discount = 0;
if (quoteLine.Attributes.Contains("manualdiscountamount"))
{
discount = (decimal)quoteLine.Attributes["manualdiscountamount"];
}
decimal amountVatExcluded = baseAmount - discount;
decimal vatAmount = amountVatExcluded * vatPercentage;
decimal amountVatIncluded = amountVatExcluded + vatAmount;
var quotelineUpdated = new Entity(quoteLine.LogicalName, quoteLine.Id);
quotelineUpdated.Attributes["capdcx_valueaddedtaxexcluded"] = new Money(amountVatExcluded);
quotelineUpdated.Attributes["capdcx_valueaddedtax"] = new Money(vatAmount);
quotelineUpdated.Attributes["extendedamount"] = new Money(amountVatIncluded);
service.Update(quotelineUpdated);
tracing.Trace("Succesfully set amounts of quoteLine");
// onCreate en onSave
}
private decimal GetVatPercentage(Entity quoteLine, IOrganizationService service)
{
Guid vatId = (Guid)quoteLine["capdcx_valueaddedtax"];
ColumnSet attributesVatEntity = new ColumnSet(new string[]
{
"capdcx_valueaddedtaxpercentage"
});
Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", vatId, attributesVatEntity);
//Entity vatEntity = service.Retrieve("capdcx_valueaddedtax", (Guid)quoteLine["capdcx_valueaddedtax"], new ColumnSet("capdcx_valueaddedtaxpercentage"));
decimal vatPercentageAsWholeNumber = 0;
if (vatEntity.Attributes.Contains("capdcx_valueaddedtaxpercentage"))
{
vatPercentageAsWholeNumber = (decimal)vatEntity.Attributes["capdcx_valueaddedtaxpercentage"];
}
decimal vatPercentage = vatPercentageAsWholeNumber / 100;
return vatPercentage;
}
Thanks a lot!
Regards,
malliendk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论