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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to retrieve record from a Form into another Form ?

(0) ShareShare
ReportReport
Posted on by 309

Hello guys,

I'm sorry the title looks confusing. The story behind is : 

1. I have a Form (FormA) which in it has a grid that listing out my table (tableA)

2. In this form Action Pane, I have a Display Menu Item which call another Form (FormB)

3. This FormB is also having grid to list out my other table (TableB), and it has a field "connection" to TableA by means there is a information in TableA that keep also in TableB (Field X)

So the idea is when I click the button in Action Pane, TableB listing should be filtered based on current record selected in my FormA, How to make FormB get the FieldX from FormA ?

Please advice.

Thanks

I have the same question (0)
  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    Hi Axel Cage,

    On the Form A Display menu item property - Set the datasource to TableA.

    Now in the Form B - Override init method and add the below code to get the caller record.

    Public void init()
    {
        // decalre tableBuffer globally..
        tableBuffer = element.args().record();// this will return the caller buffer which is TableA.
    }

    So on the TableB >> Datasource method - Override executeQuery method to filter records on TableB based on TableA(TableA buffer you already got in the init method - Use this buffer to set the range).

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    It should work without any code if you add a relation between TableA and TableB.

  • Axel Cage Profile Picture
    309 on at

    Hi Girish,

    The "declare table buffer globally", it is mean I should declare on the top, right ? I'm not sure where my mistake but it looks the table don't have value when it is inside ExecuteQuery. 

    I create something like this : 

    [Form]
    public class MySumInvoiceByCust extends FormRun
    {
        TableA	TableA;
    
        [DataSource]
        class MySumInvoiceByCust 
        {
            /// 
            ///
            /// 
            public void init()
            {
                super();
                
                TableA = element.args().record();
                
                MySumInvoiceByCust.linkPhysicalTableInstance(TableB);           
                
               
            }
    
            /// 
            ///
            /// 
            public void executeQuery()
            {
                CustInvoiceJour CustInvoiceJour;
    
                delete_from TableB;
                
                while select CustInvoiceJour where CustInvoiceJour.Invoice == TableA.InvoiceId
                {
                    [code]	
                    TableB.insert();
                }
    
                super();
            }
    
        }
    
    }

    When I tried to debug, if in Init() method, my tableBuffer TableA is populated correctly. but in ExecuteQuery(), if I take a look at the debug-watch there is no TableA hence the ExecuteQuery also return empty records. But it is no error, it doesn't hint that TableA not recognize in ExecuteQuery (I mean during Build).

    Please help.

    Thanks

  • Axel Cage Profile Picture
    309 on at

    Hi Martin,

    Unfortunately I cannot add relation with this field. It's just an additional information from my Custom table.

    Thanks

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    Then you'll need to take the value from args.record(), as Girish suggested.

    You said that your goal is filtering the data source, which is nothing about deleting and inserting records. Instead, you should add a filter to the query. For example, you can do this in init() of MySumInvoiceByCust data source:

    this.queryBuildDataSource().addRange(TableB, AField).value(queryValue(tableA.InvoiceId));

    If you need something else than "TableB listing should be filtered based on current record selected in my FormA", please describe your actual requirement.

  • Verified answer
    GirishS Profile Picture
    27,843 Moderator on at

    Hi Axel Cage,

    Buffer name for the table should be meaningful. Don't declare the buffer name same as table name. I guess you need to the populate the temp table data in the init method itself.  Also change the buffer name and check.

    Thanks,

    Girish S.

  • Axel Cage Profile Picture
    309 on at

    Hi both,

    The table inserted is a TempTable. (TableB)

    I'm now move all the code in ExecuteQuery() to Init(). 

    [Form]
    public class MySumInvoiceByCust extends FormRun
    {
        TableA	varTableA;
    
        [DataSource]
        class MySumInvoiceByCust 
        {
            /// 
            ///
            /// 
            public void init()
            {
                super();
                
                varTableA = element.args().record();
    
    	    CustInvoiceJour CustInvoiceJour;
    
                delete_from TableB;
                
                while select CustInvoiceJour where CustInvoiceJour.Invoice == TableA.InvoiceId
                {
                    [code,field assignment]	
                    TableB.insert();
                }
                
                MySumInvoiceByCust.linkPhysicalTableInstance(TableB);           
                
               
            }
    
            /// 
            ///
            /// 
            public void executeQuery()
            {            
    
                super();
            }
    
        }
    
    }

    Hi Girish, for the tablebuffer name,it was actually not the same in my actual code, so I tried to not change it as it is already different.

    However after moving it. I ran into this notification :

    "Cannot execute the required database operation.

    The method is only applicable to TempDB table variables that are not linked to existing physical table instance"

    Do you guys know what is wrong ? Thanks

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    You've never declared TableB. Does it mean that you have TableB data source and that you want both TableB and MySumInvoiceByCust data sources to be linked to the same TempDB table? Or do you want to use just one of them and therefore your current approach is logically wrong?

  • Axel Cage Profile Picture
    309 on at

    Hi Martin,

    It's MySumInvoiceByCust datasource using TableB and it is a TempDB table.

    And I guess I resolved it now. As you are referring also, then I declare TempDB as another variable first then make the insertion to this table variable.

    The linkPhysical is then using the new table variable.

    It works now.

    Thank you so much to both for guide me.

  • Verified answer
    Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    Note that you don't need tableB variable and linkPhysicalTableInstance() at all in your current implementation. You could simply insert data into mySumInvoiceByCust.

    public void init()
    {
    	super();
    	
    	Table tableA = element.args().record();
    
    	CustInvoiceJour custInvoiceJour;
    
    	while select custInvoiceJour
    		where custInvoiceJour.Invoice == tableA.InvoiceId
    	{
    		[code,field assignment]	
    		mySumInvoiceByCust.insert();
    	}
    }

    You may need linkPhysicalTableInstance() if you move the calculation outside of the form (which is usually a good idea).

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans