Skip to main content

Notifications

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++

(3) ShareShare
ReportReport
Posted on by 936

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);
}

}

  • Ali AbdAlNasser Profile Picture
    394 on at
    how to refresh the callerform datasource in d365 using x++
    I tried the solution that Martin Dráb proposed, and everything worked well.
  • Suggested answer
    Navneeth Nagrajan Profile Picture
    1,458 Super User 2025 Season 1 on at
    how to refresh the callerform datasource in d365 using x++
    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.
     
  • CU01072309-0 Profile Picture
    2 on at
    how to refresh the callerform datasource in d365 using x++
    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
    Sergei Minozhenko Profile Picture
    23,091 on at
    RE: how to refresh the callerform datasource in d365 using x++

    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();
    }

  • Suggested answer
    Martin Dráb Profile Picture
    232,871 Most Valuable Professional on at
    RE: how to refresh the callerform datasource in d365 using x++

    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
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: how to refresh the callerform datasource in d365 using x++

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,127 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans