Make a field mandatory, with a Chain of Command- X++ D365FO

443 Views Asked by At

I have a "Field1_" check box field inside the "Table1_" table. If Field1_ is set to yes, it must make it mandatory to fill in the "Field2_" field within the "Table2_" table. My idea was to make a Chain of Command on the "Table2_" of the "ValidateWrite" method, so that if the user tries to save without having filled in the "Field2_" an Alert comes out.

So far I've written something like this:

[ExtensionOf(tableStr(Table2_))]
final class Table2__Table_Extension
{
    public boolean validateWrite(boolean _skipCreditLimitCheck)
    {
        boolean continueOnError = false; 
        boolean ret = next validateWrite();
        
        Table1_ table1 = Table1_::find(this.ProjId);
        
        if (table1.Field1_)
        {
            if (!this.Field2_)
            {
                if (continueOnError)
                {
                    error("@SYS98197");
                }
                else
                {
                    throw error("@SYS23020");
                }
            }
        }
        
        return ret;
    }

}
0

There are 0 best solutions below