Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : ZuBLn+L+jLfnv+jaZB0Ptr
Finance | Project Operations, Human Resources, ...
Suggested answer

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

Like (3) ShareShare
ReportReport
Posted on 11 Aug 2020 11:52:22 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
    363 on 16 Feb 2025 at 12:19:09
    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,452 Super User 2025 Season 1 on 02 Jul 2024 at 07:53:06
    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 01 Jul 2024 at 23:28:14
    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 11 Aug 2020 at 12:15:35
    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
    231,760 Most Valuable Professional on 11 Aug 2020 at 12:10:57
    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,156 Moderator on 11 Aug 2020 at 12:06:11
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,760 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans