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

Pass values from Form B to Form A - X++

(0) ShareShare
ReportReport
Posted on by 65

How to pass values from Form B to Form A. The scenario is I'm going to click Settle Transactions which opens a new form and it will show a list which I can mark. After mark item and click save, I want to pass the marked values to Form B.

Form : LedgerJournalTransVendInvoice
Control Name : ButtonSettlement
8233.png


Form Name : VendOpenTrans
Control Name : Save

3660.png

Planning to pass the value invoice to Form A
33566.png


Is it possible to use an event handler to control VendOpenTrans.Save then pass it to Form A?

Thanks in advance

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    In init method of form B, you can access the caller form A (FormRun class instance) via element.args().caller().

    Once you have the caller, you can access anything in form A, including controls, data sources and (public) methods.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    And, of course in Form B you can send info back to Form A, because you have the pointer to it.

  • jerrold-verzosa Profile Picture
    65 on at

    [FormControlEventHandler(formControlStr(VendOpenTrans, Save), FormControlEventType::Clicked)]
    public static void Save_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        //Access Invoice column in VendOpenTrans and pass it to LedgerJournalTransVendInvoice
    }

    How am I going to use the pointer in the event handler?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Use sender.formRun() to get FormRun of current form. Once you have that, call formRun.args().caller() to get the caller formRun.

  • jerrold-verzosa Profile Picture
    65 on at

    FormRun _formRun   = sender.formRun();
    FormRun callerForm = _formRun.args().caller();
    
    //Object reference not set to an instance of an object
    FormDataSource _ledgerJournalTransVendInvoice = callerForm.dataSource(formDataSourceStr(LedgerJournalTransVendInvoice, LedgerJournalTrans));
    


    Tried this but the callerForm object returns null.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    This should work normally, but of course only when form B is opened directly from form A, and caller is passed via args.

    I don't have a system at hand, but please look what the button in the first form calls. Most likely by looking at the button (menu item, clicked method) you will understand what pieces are involved and how to adjust your code.

    You can also put a breakpoint in the init method of form B, and check the call stack with debugger.

    Please share all your findings with us.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    I checked it a bit, and indeed in this case "caller" object is not provided to the settlement form.

    The args are defined in Classes\LedgerJournalEngine\createArgsForSettlementForm.

    To me it seems that the caller form is passed to LedgerJournalEngine class (via _formRun variable in constructor method).

    So, you could try to use Chain of Command in the createArgsForSettlementForm, and put that formRun variable in args.caller(). However that could cause some unexpected behavior which you would find out in testing.

    If there are issues, you could pass it via args.object() and handle it accordingly on form B.

  • Suggested answer
    jerrold-verzosa Profile Picture
    65 on at

    Hello Nikolaos, below is my solution.

    You need to do create a form extension for VendOpenTrans and implement Chain of Command in init() and create a method that has a return value of LedgerJournalTrans,

    [ExtensionOf(formStr(VendOpenTrans))]
    final class VendOpenTrans_Extension
    {
        public LedgerJournalTrans       _LedgerJournalTrans;
        
        public void init()
        {
            next init();
    
            switch (originator.TableId)
            {
                case tableNum(LedgerJournalTrans):
                    _LedgerJournalTrans = this.args().record();
                    break;
            }
        }
        
        public LedgerJournalTrans getLedgerJournalTrans()
        {
            return _LedgerJournalTrans;
        }
    }


    Second step is you need to implement an EventHandler for the control Save in VendOpenTrans.

    [FormControlEventHandler(formControlStr(VendOpenTrans, Save), FormControlEventType::Clicked)]
    public static void VendOpenTransSave_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        FormRun                     _formRun                    = sender.formRun();
        FormDataSource              _vendTransDS                = _formRun.dataSource(formDataSourceStr(VendOpenTrans, VendTrans));
        VendTrans                   _vendTrans                  = _vendTransDS.cursor();
        LedgerJournalTrans          _ledgerJournalTrans;
    
        _ledgerJournalTrans								    = _formRun.getLedgerJournalTrans(); //Method that you created from VendOpenTrans extension
        //Pass the value from form B to form A
        _ledgerJournalTrans.Invoice						    = _vendTrans.Invoice;
    }




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 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans