如果其中任何一个不正确或不需要,请原谅,我对x ++开发还是很陌生。我正在尝试向SalesOrderLineEntity添加一些验证,以阻止用户导入无法被多个数量整除的数量。这就是我已经走了多远,我不能锻炼如何用x ++编写(如果订购的数量不能被多个数量(即不是整数)整除)然后抛出错误...任何帮助将不胜感激!谢谢。
[ExtensionOf(tableStr(SalesOrderLineEntity))]
final class SalesOrderLineEntity_Extension
{
boolean validateWrite()
{
InventItemSalesSetup inventItemSalesSetup;
SalesLine salesLine;
SalesTable salesTable = SalesTable::find(this.SalesOrderNumber);
select firstonly * from salesLine where salesLine.salesid == salesTable.SalesId
join inventItemSalesSetup where inventItemSalesSetup.ItemId == salesLine.ItemId;
if (this.RecId)
{
if (salesLine.QtyOrdered < inventItemSalesSetup.MultipleQty)
{
return checkFailed
("qty ordered less than multiple qty");
}
if (isInteger(salesLine.QtyOrdered / inventItemSalesSetup.MultipleQty))
{
return checkFailed
("qty ordered not divisible by multiple qty");
}
}
next validateWrite();
if (!salesTable.checkUpdate(true, true, true))
{
return false;
}
boolean ret;
//ret = super();
return ret;
}
}
答案 0 :(得分:3)
如果使用整数,则需要在AX中使用取模运算(mod
)。确保检查您没有除以零(世界可能会终结),并且可能要检查是否确实输入了非零数量。
if(salesLine.QtyOrdered && inventItemSalesSetup.MultipleQty && (salesLine.QtyOrdered mod inventItemSalesSetup.MultipleQty != 0)
{
return checkFailed("qty ordered not divisible by multiple qty");
}
如果您使用实数,那么您想做一些基本的整数数学。
real qtyOrdered;
real multipleQty;
int result;
qtyOrdered = 321.0; // 321 / 10.7 = 30 exactly
multipleQty = 10.7;
result = qtyOrdered / multipleQty; // This will store the integer and drop any decimals
// If the result multipled by the original multiple is equal to the original value, then you're good
if (result * multipleQty == qtyOrdered)
{
info("All good!");
}
else
{
info("Bad!");
}
可能是可以执行您想要的功能的标准AX函数,但是它很基础,我自己自己做数学即可。
答案 1 :(得分:0)
请查看完成的代码,我相信这是我现在想要的。谢谢您的帮助。任何建议/效率/改进,将不胜感激!
[ExtensionOf(dataentityviewstr(SalesOrderLineEntity))]
final class SalesOrderLineEntity_Extension
{
boolean validateWrite()
{
InventItemSalesSetup inventItemSalesSetup;
SalesLine salesLine;
select firstonly * from salesLine where salesLine.Salesid == this.SalesOrderNumber
&& salesLine.ItemId == this.ItemNumber
join inventItemSalesSetup where inventItemSalesSetup.ItemId == this.ItemNumber;
boolean ret = next validateWrite();
if (ret)
{
if (ret && this.OrderedSalesQuantity < inventItemSalesSetup.MultipleQty)
{
ret = checkFailed ("qty ordered less than multiple qty");
}
if (ret && this.OrderedSalesQuantity mod inventItemSalesSetup.MultipleQty != 0)
{
ret = checkFailed ("qty ordered not divisible by multiple qty");
}
}
return ret;
}
}