Hi
I have a new field ReasonCode which is added to the SalesLine. If the salesQty (CreditNote) is less than ) this field is mandatory.
I have added the code to the SalesTable form Salesline_ds on the validate_write, but this will then only execute if the salesline record is modified. I can ot add it to the Tables validate write, because the salesline gets created from different places and I do not want to have to add this field on all the table from where a salesline is created.
So I was thinking of adding the validation on the onClicked of the ConfirmButton. Hoping that if it fails then I can throw an exception and not allow the confirmation form to open.
However it first opens the Form and then runs through my code. How can I prevent this form from opening by forcing that the validation I added on the OnClicked method be done before opening the form.
Oh and I have the same validation on the Return order
Any advice will be appreciated. See my code
[FormControlEventHandler(formControlStr(SalesTable, buttonUpdateConfirmation), FormControlEventType::Clicked)]
public static void buttonUpdateConfirmation_OnClicked(FormControl sender, FormControlEventArgs e)
{
SalesTable salesTable;
SalesLine salesLine;
FormRun formRun = sender.formRun() as FormRun;
FormDataSource salesTable_ds;
salesTable_ds = sender.formRun().dataSource(1);
salesTable = salesTable_ds.cursor();
select SalesId, ItemId, RecId from salesLine
where salesline.salesid == salesTable.salesId
&& salesLine.SalesQty < 0
&& salesline.PBFReturnReasonCodeId == '';
if(salesLine.RecId)
{
throw error('Return reason code is mandatory for line with item :' salesLine.ItemId);
}
}