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

CloseOK calls the cancel button of caller form

(0) ShareShare
ReportReport
Posted on by

Hello community,

When posting a sales invoice I am adding a specific development :

Open new Form when clicking on OK button in Form SalesEditLines

pastedimage1601395903113v1.png

The new form is a Dialog type with some traitment and conditions : When Clicking on OK Button on this new Form the invoice Posting will proceed, and when clicking on Cancel Button this form and the form SalesEditLines should be closed and the invoice posting should be cancelled.

pastedimage1601396170855v2.png

I made an extension class of the method Clicked of the OK button in the form SalesEditLines as following to open the form.

My Question is : If I will Choose Cancel in my New Form how can I Cancel the call of OK Button or the invoice posting, or the CloseOK of the form SalesEditLines ?! 

Is it possible or Not? If Yes please where should I place my Code

I have the same question (0)
  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    I see neither images nor your code. Could you fix it, please?

  • Community Member Profile Picture
    on at

    Here is the code :But I think I should place the code some where else to cancel posting invoice. I don't know where

    [ExtensionOf(formControlStr(SalesEditLines, OK))]

    final class SalesEditLinesOKButton_PG_F_Extension

    {

       public void clicked()

       {

            Info ("Traitement A");

            this.runPreValidationTraitment();

            next clicked();

            Info ("Traitement B");

       }

       public void runPreValidationTraitment()

       {

           Args                            args;

           Object                          formRun;

           // open form

           FormDataSource SalesParmTable_ds=element.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)) as FormDataSource;

           SalesParmTable SalesParmTable=SalesParmTable_ds.cursor();

           SalesTable salesTable=SalesTable::find(SalesParmTable.SalesId);

           args = new Args();

           args.record(salesTable);

           args.name(formstr(TestFrom));

           formRun = classfactory.formRunClass(args);

           formRun.init();

           formRun.run();

           formRun.wait();

           if (!formRun.CloseOK())

           {

           // Do not Post invoice and cancel OK button

           }

       }

    }

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    First of all, let me make your code easier to read. Please always use Insert > Insert Code (in the rich formatting view) to paste source code.

    [ExtensionOf(formControlStr(SalesEditLines, OK))]
    final class SalesEditLinesOKButton_PG_F_Extension
    {
    	public void clicked()
    	{
    		info ("Traitement A");
    		this.runPreValidationTraitment();
    		next clicked();
    		Info ("Traitement B");
    	}
    	
    	public void runPreValidationTraitment()
    	{
    		// open form
    		FormDataSource salesParmTable_ds = element.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)) as FormDataSource;
    		SalesParmTable salesParmTable = salesParmTable_ds.cursor();
    		SalesTable salesTable = SalesTable::find(SalesParmTable.SalesId);
    		Args args = new Args();
    		args.record(salesTable);
    		args.name(formstr(TestFrom));
    		
    		Object formRun = classfactory.formRunClass(args);
    		formRun.init();
    		formRun.run();
    		formRun.wait();
    		if (!formRun.closeOK())
    		{
    			// Do not Post invoice and cancel OK button
    		}
    	}
    }

    Your design is wrong. You can't skip the standard code from CoC and clicked() method is a wrong place for such business logic anyway.

    I think the best place would be validate() method of the appropriate SalesFormLetter class, such as SalesFormLetter_Confirm.

  • Community Member Profile Picture
    on at

    If I make the return of the validate() method to false it will not post the invoice and it will not close the form SalesEditLine. I want to cancel the posting if I choose cancel in my new form.

    Hope you understand what I mean

  • Suggested answer
    Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Hmm, it sounds it does what you want. You want to cancel posting if you click Cancel, which you'll achieve by returning false from validate(). What's the problem?

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans