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

how to refresh the callerform datasource in d365 using x++

(4) ShareShare
ReportReport
Posted on by 950

hi all,

i am having formA and form B (both custom forms.) Form A contains Table A, TableB(header n line). Form B contains Table B only(a dialog form).

when i click on new button(its a menu item button) from Form A it opens FormB. when i create the record in the dialog form, when i click on Ok button. i need to refresh the Table B of formA.

i hav written the below code in Form B and called it in OK button of Form B. its refreshing the table A instead of Table B. any suggestions pls..

private void CallerFOrmDS_Refresh()
{
Object calleform;
FormDataSource fds;

calleform = element.args().caller();

fds = element.args().record().datasource();
if(calleform)
{
fds.refresh();
fds.research(true);
}

}

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

    In form A you can decide which data source you assign with the button. This can be set in the Data source property of the menu item (or the button group where the button is). So, if you set Table B as data source for your button, then your code will refresh data source for Table B.

    There's also a property in the button to auto refresh data source, it works in many scenarios. Then you would not have to write any code.

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

    If element.args().record() is a record of Table A, it means that the data source used for the menu item button is Table A. Change its Data Source property to Table B.

    By the way, let me improve your code a bit:

    private void CallerFOrmDS_Refresh()
    {
        FormDataSource fds = FormDataUtil::getFormDataSource(element.args().record());
        if (fds)
        {
            fds.research(true);
        }
    }

    Next time, use Insert > Insert Code (in the rich formatting view) to paste source code, as I did.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi TestBot,

    In case if you still need to use data source A as caller datasource and form A is your form, you can add interface IFormRefreshable to your form and implement method callerRefresh on the form, where you can define refresh logic. When the dialog is closed you can call callerRefresh method from this form.

    //Form 
    [Form]
    public class MyForm extends FormRun implements IFormRefreshable
    ....
    public void callerRefresh()
    {
        Table2_DS.research(); //or executeQuery
    }
    
    ...
    
    //Dialog close action
    IFormRefreshable callerform = element.args().caller() as IFormRefreshable;
    
    if (callingForm != null)
    {
        callingForm.callerRefresh();
    }

  • CU01072309-0 Profile Picture
    2 on at
    Hello,
    To refresh Table B, you need to modify the code as follows:
     
    csharp
    private void CallerFormDS_Refresh()
    {
        FormRun callerForm;
        FormDataSource callerFormDS;
        callerForm = element.args().caller();
        if (callerForm)
        {
            callerFormDS = callerForm.dataSourceByName("TableB"); // Replace "TableB" with the actual name of the Table B data source in Form A
            if (callerFormDS)
            {
                callerFormDS.refresh();
                callerFormDS.research(true);
            }
        }
    }
     
    In the modified code, we retrieve the data source for Table B in Form A using its name (replace "TableB" with the actual name of the Table B data source in Form A). Then we perform the refresh and research operations on that specific data source.
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    2,407 Super User 2025 Season 2 on at
    Hi Shaik146.
     
    Because your refresh of data should be on TableB, the element.args.caller() as Martin mentioned should be on TableB. To add to what Martin said, the call can be on research() method which will execute the same query again and retrieve results from the database. Also, it will provide you the latest data. 
     
    Also, agree with nmaenpaa where you can have menu items option to point to FormB and have the datasource set on the menu item. It's a feasible solution. Refreshes will be easier to manage instead of having triggers done through these screens on the database.
     
  • Ali AbdAlNasser Profile Picture
    405 on at
    I tried the solution that Martin Dráb proposed, and everything worked well.
  • Suggested answer
    nbhatti2001 Profile Picture
    222 on at
    This code has worked for me. I have pass record to my custom calss and have call this method from main method of class and has pass same parameter which main method as received and it worked.
     

    private static void getRefreshData(Args _args)

       {

           Object calleform;

           FormDataSource fds;

           calleform = _args.caller();

           fds = _args.record().datasource();

           if(calleform)

           {

               fds.refresh();

               fds.research(true);

           }

       }

  • Ahmed Alam Profile Picture
    62 on at
     
    I have same concern. Where to add your code on which level (Parent or Child).
  • Martin Dráb Profile Picture
    237,807 Most Valuable Professional on at
    The requirement was to refresh the caller from the child form, therefore my code does the same.
     
    You could do it from the parent form too, though. You'd wait for the dialog form to close and then simply call research() on the data source, e.g. tableA_ds.research(true).

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans