Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 10657

Refreshing form parts

$
0
0

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

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:

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

Viewing all articles
Browse latest Browse all 10657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>