【问题标题】:Dynamics 365 Finance and Operations SalesOrderLineEntity validation extensionDynamics 365 Finance and Operations SalesOrderLineEntity 验证扩展
【发布时间】:2019-02-14 14:40:55
【问题描述】:

我还是 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;

}

}

【问题讨论】:

    标签: axapta x++ dynamics-365-operations


    【解决方案1】:

    如果使用整数,则需要在 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 函数可以满足您的需求,但它太基础了,我只能自己算算。

    【讨论】:

      【解决方案2】:

      请查看完成的代码,我相信这正在做我想做的事。谢谢您的帮助。对此的任何建议/效率/改进将不胜感激!

      [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;
      
      }
      

      }

      【讨论】:

        猜你喜欢
        • 2020-05-02
        • 1970-01-01
        • 1970-01-01
        • 2020-12-02
        • 2017-07-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-16
        • 2022-06-15
        相关资源
        最近更新 更多