I'll try to explain my goal briefly. My code should display a NoYes pop up when I click on a button and a certain condition happens, If I press Yes the code keep going, if I press No it stops. I used a Chain of Command class, as an axtension of the button on my form, This is my code:
[ExtensionOf(formControlStr(VendEditInvoice, OK))]
final class VendEditInvoice_OK_AzimutBenetti_Extension
{
public void clicked()
{
IntentLetter_IT intentLetter;
VendInvoiceInfoLine vendInvoiceInfoLine;
Info(strFmt('%1, %2', vendInvoiceInfoLine.LineAmount, intentLetter.remainAmountMST()));
if(vendInvoiceInfoLine.LineAmount >= intentLetter.remainAmountMST())
{
DialogButton diagBut;
str strMessage = "Importo da decurtare al saldo della lettera di intento maggiore dell’importo residuo. Proseguire?";
str strTitle = "Splafonamento";
diagBut = Box::yesNo(
strMessage,
DialogButton::No,
strTitle
);
if(diagBut == DialogButton::No)
{
//return;
info('Operazione annullata');
throw error('Operazione annullata');
}
}
next clicked();
}
}
If I put the Return inside the second if, I get this error once I build the project: call to 'next' should be done only once and unconditionally. I assume that's because if I press No, the code returns and the method next is never called, because if I delete Return and put for example an info, everything works fine. I tried with a throw error as you can see, but, even if it works, I think that is not the correct way to do it, cause there is no real error or exception, when I presso NO . How Can i do it in a different way that works? Thank you very much.
You can probably use EventHandler and FormControlCancelableSuperEventArgs
Take a look at https://stoneridgesoftware.com/use-event-handlers-to-override-a-form-control-lookup-method-in-dynamics-365-finance-and-operations/