views:

302

answers:

1

In most cases, validation methods I've overridden execute twice each time the parent field is changed. Everything still works, but the InfoLog displays double messages every time.

Is there any way to prevent this?

Thanks

public boolean validate()
{
    boolean ret;
    int exlowValue;
    int lowValue;
    int highValue;
    int exhighValue;
    str errorMessage;
    ;

    ret = super();

    //Make sure a numeric value was entered
    if (ABC_RegExValidator::validateMe("integer",  int2str    (ABC_Checks_checkExtremeLow.value())))
    {
        //get the form values
        exlowValue = ABC_Checks_checkExtremeLow.value();
        lowValue = str2int(ABC_Checks_checkLow.valueStr());
        highValue = str2int(ABC_Checks_checkHigh.valueStr());
        exhighValue = str2int(ABC_Checks_checkExtremeHigh.valueStr());

        //Extreme Low must be 0 or less than all others
        if (exlowValue != 0)
        {
            //A non-zero value was entered; it must be less than all other fields
            if ((exlowValue >= lowValue && lowValue > 0) || (exlowValue >= highValue && highValue > 0) || (exlowValue >= exhighValue && exhighValue > 0))
            {
                //Return an error
                ret = checkfailed(strFmt("@ABC197", int2str(exlowValue)));
            }
            else
            {
                //Not greater than any other value
                //Success!
                ret = true;
            } //Greater than all others?
        }
        else
        {
            //No errors
            ret = true;
        } // 0?
    }
    else
    {
        //Regular expression failed
        //Return an error
        ret = checkfailed("@ABC192");
    } //Regular expression


    return ret;
}
A: 

Your description of the problem is not really clear. One can override the valite method on a form control, the validate method on a form datasource and the validatefield method on the table. That's my knowledge of version 3.0. And how do you mean the "parent field"? I presume the table field?

If I put info messages in each of these methods they only execute once when I modify a value. That's the case in 3.0. I don't know which version you're using.

Maybe you could be more precise about which validation method you're testing?

_pointer
Using Dynamics AX 2009. I am overriding the validate event on the form fields (stringedit, intedit, combobox, etc.) themselves, rather than the datasource or table. I placed an info() statement at the very start of the validate routine, and it will displays once if the field passes validation, but always twice if validation fails. The code is fairly simple:public boolean validate(){ boolean ret; ; ret = super(); if ( ..statement.. ) { ret = checkfailed(strFmt("@SPC197"); } else { ret = true; } return ret;}
Brad
In your comment you mention that you have an info() statement at the start of the method. However, the info() statement is not part of your code example. This confuses me. If you are using the info() statement in conjunction with the checkFailed() statement then this is where the problem is. The checkFailed() statement also uses the Infolog system to display warnings. Eliminate the checkfailed and simply use ret = false. If this still is not the answer then please can you post the complete code example?
_pointer
The info() was just for testing, and thus, wasn't included in the code I posted. Not using info() during the validation itself, only checkfailed. Code is now available. See above.
Brad
I can't see why the messages should appear twice. You could double check the validateMe method to see if any messages come from there. Btw, you should check the result of the super() call. If this returns false you should skip your code block and return false.
_pointer
Will do. Thanks for the help.
Brad