web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Next call on Chain of Command

(1) ShareShare
ReportReport
Posted on by 71
Hi everyone,
I'll try to explain briefly my goal. My code should display a NoYes pop up when I click on a butto 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;                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;            }        }        next clicked();    }}

But 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. How Can i do it in a different way that works? 
Thank you very much.
I have the same question (0)
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    You can skip next call, but you can throw an exception. If you want an exception without an infolog message, use throw Exception::Error.
     
    Also, look into the logic called by this button; maybe you'll find a better place for your dialog.
     
    By the way, you clearly intended to populate intentLetter and vendInvoiceInfoLine variables, but you didn't, therefore your check won't do anything useful.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Instead of return, you can simply throw an error like below.
    [ExtensionOf(formControlStr(VendEditInvoice, OK))]
    final class VendEditInvoice_OK_AzimutBenetti_Extension
    {
        public void clicked()
        {        
    		IntentLetter_IT intentLetter;        
    		VendInvoiceInfoLine vendInvoiceInfoLine;                
    		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;
    						throw error("//some message");
    					}       
    			}        
    			next clicked();
    	}
    }
     
    So, if no is pressed, it will throw error and button execution won't happen further.
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hello @Fabrizio,
     
    You can't skip the Next call and you can't put in condition so try to call it before your logic if it is applicable or give me more details about what you want to achieve. in order to help you more
     
      
    Regards,
    Waed Ayyad
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • FabFab97 Profile Picture
    71 on at
    Thanks everyone,
    The solution with the Throw Error seems to work, but my boss told me that it's not the most correct way. That's because when i click on NO there isn't an exception or an error, but the registration of the journal must stop anyway. I don't know if I've been clear enough. So do you know id there is any other way to do it?
    I don't know if using an event handler instead of a chain of command may be of any help maybe?
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    I don't understand the problem with clicking No, but if you don't want this approach, then implementing your solution it in clicked() is impossible. Event handlers won't help you either, because their allow just adding extra logic, not skipping the existing code. Throwing an exception would be the only solution there.
     
    Then you can either give up the whole thing, or just your current approach. You would have to find a better place for your logic. I would avoid clicked() anyway, but I can't give you a more specific piece of advice without looking at the actual code. For example, it may call form's canClose() method, or the form letter framework may have a validation method you could extend.
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    If there is an error on clicking a button, then the process will stop. If it is not stopping have you debugged it? Can you send your code here with throwing exception?
  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    A good place for your logic seems to be canProceedWithInvoicePosting() method of VendEditInvoice form. You can create a CoC extension, add the dialog below next and return false if you want to stop the process.
  • FabFab97 Profile Picture
    71 on at
    Hi everyone, it's me again. 
    This is my code now, I'm using the canProceedWithInvoicePOsting() method as suggested by @Martin Dràb, but I still get an error once i click Yes on my pop-up. This is my code now:

    [ExtensionOf(formControlStr(VendEditInvoice, OK))]

    final class VendEditInvoice_OK_AzimutBenetti_Extension

    {

        private boolean canProceed = true;

     

        public void clicked()

        {

            IntentLetter_IT intentLetter;

            VendInvoiceInfoLine vendInvoiceInfoLine;

     

            Amount totalAmount;

            Amount remainingAmount;

            RecId intentLetterRecId;

     

            // Ciclo attraverso tutte le fatture

            while select * from vendInvoiceInfoLine

            {

                totalAmount = vendInvoiceInfoLine.LineAmount;

                intentLetterRecId = vendInvoiceInfoLine.RecId;

     

                select firstOnly intentLetter

                    where intentLetter.RecId == intentLetterRecId;

     

                remainingAmount = intentLetter.remainAmountMST();

     

                Info(strFmt('%1, %2', totalAmount, remainingAmount));

     

                if (totalAmount >= remainingAmount)

                {

                    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)

                    {

                        canProceed = false;

                        info('Operazione annullata');


                    }

                }

            }

    next clicked();

        }

     

        public boolean canProceedWithInvoicePosting()

        {

            return canProceed;

        }

     

        public void setCanProceed(boolean _canProceed)

        {

            canProceed = _canProceed;

        }

    }

    but i get this error: Code execution error: Form Button Control (object), clicked method called with invalid parameters

    anyone knows why? 
    Can it be because of the while select loop? 
    Thank You.
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    Unfortunately I see no code in your reply; please add it.
     
    Also, please tell where the thrown from. For example, look at the exception in debugger and check its StackTrace property.
  • FabFab97 Profile Picture
    71 on at
    Sorry, here is my code

    [ExtensionOf(formControlStr(VendEditInvoice, OK))]
    final class VendEditInvoice_OK_AzimutBenetti_Extension
    {
        private boolean canProceed = true;
     
        public void clicked()
        {
            IntentLetter_IT intentLetter;
            VendInvoiceInfoLine vendInvoiceInfoLine;
     
            Amount totalAmount;
            Amount remainingAmount;
            RecId intentLetterRecId;
     
            // Ciclo attraverso tutte le fatture
            while select * from vendInvoiceInfoLine
            {
                totalAmount = vendInvoiceInfoLine.LineAmount;
                intentLetterRecId = vendInvoiceInfoLine.RecId;
     
                select firstOnly intentLetter
                    where intentLetter.RecId == intentLetterRecId;
     
                remainingAmount = intentLetter.remainAmountMST();
     
                Info(strFmt('%1, %2', totalAmount, remainingAmount));
     
                if (totalAmount >= remainingAmount)
                {
                    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)
                    {
                        canProceed = false;
                        info('Operazione annullata');
                    }
                }
            }
            next clicked();
        }
     
        public boolean canProceedWithInvoicePosting()
        {
            return canProceed;
        }
     
        public void setCanProceed(boolean _canProceed)
        {
            canProceed = _canProceed;
        }
    }
     
    I can't access to the Vm right now so I can't debug, if you still need it I'll do it tomorrow Asap.
    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans