Hi,
So the requirement is to do some validations on each sales line before confirming the order.
if the enum XType value is Must, then an error should be returned.
However, if the XType value is option, then a warning should appear but, the process should proceed.
I did this, but i have two issues/concerns:
1. Is this the best place to perform such validation? and if it's the best place, shall i use _calledFrom for anything?
2. i want all warnings to appear, but currently the first warning would only be returned and it won't continue and return all warnings. So for example if the Xtype is optional for all lines in the sales order, then i want all warnings to appear, so that after confirming the user can look at all warnings and amend the value
[ExtensionOf(classStr(SalesFormLetter_Confirm))]
final class SalesFormLetter_ConfirmX_Extension
{
public boolean validate(Object _calledFrom)
{
boolean ret;
ret = next validate(_calledFrom);
if(ret)
{
SalesLine salesLine;
while select salesLine where salesLine.SalesId == this.salesTable().SalesId
{
TableX tableX;
select firstonly tableX where tableX.ItemId == salesLine.ItemId;
if(tableX)
{
this.validateFirstField(salesLine, tableX);
this.validateSecondField(salesLine, tableX);
}
}
}
return ret;
}
public void validateFirstField(SalesLine _salesline, TableX _tableX)
{
if(_tableX.FirstField == XType::Must && _salesLine.FirstField== '')
{
throw error(strFmt("The FirstField for itemId: %1, must be filled", _salesLine.ItemId));
}
else if(_tableX.FirstField== XType::Optional && _salesLine.FirstField== '')
{
checkFailed(strFmt("The FirstField for itemId: %1, is preferred be filled", _salesLine.ItemId));
}
}
public void validateSecondField(SalesLine _salesline, TableX _tableX)
{
if(_tableX.SecondField == XType::Must && _salesLine.SecondField == '')
{
throw error(strFmt("The SecondField for itemId: %1, must be filled", _salesLine.ItemId));
}
else if(_tableX.SecondField == XType::Optional && _salesLine.SecondField == '')
{
checkFailed(strFmt("The SecondField for itemId: %1, is prefered be filled", _salesLine.ItemId));
}
}
}