I need to understand the significance of a piece of code. If somebody can kindly help......

class SaleLine_Events
{

[PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, validateField))]
public static void SalesLine_Post_validateField(XppPrePostArgs args)
{
SalesLine salesLine = args.getThis();
FieldId fieldId = args.getArg("_fieldId");
boolean ret = args.getReturnValue();

switch(fieldId)
{
case fieldNum(SalesLine, LinePercent):
if (salesLine.LinePercent > 10)
{
ret = ret && checkFailed(“Line per cent is to high!”);
}
break;
}

args.setReturnValue(ret);
}

}

The line – ret = ret && checkFailed(“Line per cent is to high!”);

What is this doing exactly? It is assigning the value of ret variable to itself ?
And why is there an && with checkFailed ?..Checkfailed is basically used to output an error message right?

First of all, let me add indentation, which will make the code easier to read. Next time, please use Insert > Insert Code to paste source code.

class SaleLine_Events
{
    [PostHandlerFor(tableStr(SalesLine), tableMethodStr(SalesLine, validateField))]
    public static void SalesLine_Post_validateField(XppPrePostArgs args)
    {
        SalesLine salesLine = args.getThis();
        FieldId fieldId = args.getArg("_fieldId");
        boolean ret = args.getReturnValue();

        switch(fieldId)
        {
            case fieldNum(SalesLine, LinePercent):
                if (salesLine.LinePercent > 10)
                {
                    ret = ret && checkFailed("Line per cent is to high!");
                }
                break;
        }

        args.setReturnValue(ret);
    }
}

I’ll also add a version tag.

SalesLine_Post_validateField() is a method that will be executed after SalesLine.validateField(). It’s the old way, used before Microsoft introduced Chain of Command (CoC).
It gets a reference to the SalesLine record to be validated, field ID and the value returned from SalesLine.validateField(). If it’s validation of LinePercent field, it checks whether it’s not higher than 10 and set the return value to false it it is.

Now look at how much easier and more readable it is with CoC:

[ExtensionOf(tableStr(SalesLine))]
final class SalesLineMyLogic_Extension
{
    public boolean  validateField(FieldId  _fieldId)
    {
        boolean ret = super(_fieldId);
        
        switch(_fieldId)
        {
            case fieldNum(SalesLine, LinePercent):
                if (salesLine.LinePercent > 10)
                {
                    ret = checkFailed("Line per cent is to high!");
                }
                break;
        }
        
        return ret;
    }
}

Thanks Martin. Really kind of you to indent the code. I will make sure to use the ‘insert code’ here on. The CoC pattern definitely makes it much easier to understand. Thankyou !