Refreshing form parts

When using form parts in AX 2012, you sometimes need to explicitly refresh their data based on an event in the main form. It may not be completely obvious how to do it, but it’s not too complicated in the end.

Form parts are actually forms by themselves and if you know how to manipulate forms at runtime, you know how to work with parts too. The tricky part it getting a reference to a form part.

One of possible solutions is adding the following method to SysSetupFormRun class (so it’s available to all forms):

public FormRun getFormPartByName(str _name)
{
    PartList partList = new PartList(this);
    FormRun part;
    int i;
 
    for(i = 1; i <= partList.partCount(); i++)
    {
        part = partList.getPartById(i);
 
        if (part.name() == _name)
        {
            return part;
        }
    }
    return null;
}

As you see, it iterates all parts in the form and finds a part with the given name.

Then you can call it from your form to get a reference to a particular part and do anything you like with it, such as refreshing the data:

public void refreshMyFactBox()
{
    SysSetupFormRun formRun = this as SysSetupFormRun;
    FormRun factBox = formRun.getFormPartByName('MyInfoPart');
 
    if (factBox)
    {
        factBox.dataSource().research();
    }
}

Note that if it’s a form part, you have to provide the name of the underlying form, such as:

FormRun factBox = formRun.getFormPartByName(formStr(MyFormPartForm));

7 Comments

  1. Very small typo.
    There’s a double end parathesis in

    FormRun factBox = formRun.getFormPartByName(‘MyInfoPart’));

    There should only be one.
    Then it will compile. 🙂

  2. Hi Martin, can something like this be used to send eplicit data to a form part?

    Let me explain. I have created an InfoPart on the SalesTable form to display certain attributes for an item. The problem is, the infoPart data doesn’t display on a new SalesLine entry until it’s saved (obviously because the infoPart is reading from the SalesLine table and until I save the line, the data only exists in the table buffer). However we need the infoPart data to display immediately upon entry of the ItemId on the new SalesLine before it’s been saved. I can use a display method in the SalesLine grid and it is able to use the TableBuffer data to populate. (The text is too long to reasonably display in the grid however)

    I’ve been looking for a solution to my problem when I came across your blog post here. Could I “push” a string from aSalesLine display method to appear in the InfoPart before the line is saved/inserted into the SalesLine table?

    Thanks for your time.

  3. Hi Martin, i am working with D365 and i need to add a resizing option between the grid and the form part of the Pending Vendor Invoices list page.

    I am not sure how since the standard list page does not give a resizing option.

  4. Thank you for the response. we are checking for alternate solutions to show the lines form part in the pending invoices list page

    • Hey,
      We’re you able to find a solution for list page parts? Thank you in advance.

Comments are closed.