[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));
}
}
}
Event Handler: You can create a pre-validation event handler that triggers before the sales order confirmation process starts. In the event handler, you can implement your custom logic to check for the specific condition that would result in a failed confirmation. If the condition is met, you can throw an exception or display an error message to prevent the confirmation.
Workflow: If you prefer a configuration-based approach, you can use a workflow to validate the sales order confirmation. Create a workflow that runs before the confirmation process, and add the necessary conditions and actions to check for the specific case. If the condition is not met, you can stop the workflow, preventing the confirmation.
André Arnaud de Cal... 291,735 Super User 2024 Season 2
Martin Dráb 230,466 Most Valuable Professional
nmaenpaa 101,156