在 D365 X++ 上使用 SysOperations 进行验证

问题描述 投票:0回答:1

我是 x++ 和 D365 的新手,所以我经常陷入非常简单的任务中。在本例中,我在扩展表 EcoResProductParameter 中创建了一个名为 MaxPercentage 的新字段,并将其放入 EcoResProductParameter 扩展表单中,并且我需要检查该值是否大于我在 InventTable 中选择的 SalesPercentMarkup。如果是这样,则更新百分比,否则我将收到错误。我尝试在 DataContract 类中执行类似的操作:

public boolean validate()
{
    boolean isValid;
    if(salesPercentMarkup <= parameterTable.MaxPercentage)
    {
        isValid = true;
    }
    else
    {
        isValid = checkFailed('The percentage has exceeded the max');
    }
            
    return isValid;
}

但它不断返回错误,因为我不知道如何正确访问用户手动插入 MaxPercentage 字段的值,所以我想问题出在我的 if 语句中。谁能帮我这个?谢谢你

forms validation field x++ dynamics-365-operations
1个回答
0
投票

实现此目的的一种方法是为 validateField 表的

InventTable
方法创建
Chain of Command
扩展类。

这允许您添加自定义字段验证。在问题中描述的场景中,这可能如下所示:

[ExtensionOf(tableStr(InventTable))]
final class InventTable_Extension
{
    public boolean validateField(FieldId _fieldIdToCheck)
    {
        // execute the standard validateField logic
        boolean ret = next validateField(_fieldIdToCheck);

        // add custom validation
        if (_fieldIdToCheck == fieldNum(InventTable, SalesPercentMarkup))
        {
            EcoResProductParameters ecoResProductParameters = EcoResProductParameters::find();
            if (this.SalesPercentMarkup > ecoResProductParameters.MaxPercentage)
            {
                // note that the message should be a label and put in double quotes
                ret = checkFailed('The percentage has exceeded the max'); 
            }
        } 

        return ret;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.