Thursday, June 28, 2012

AX2012 - How to control the visibility of FactBox on form thru X++


Before discussing the code, let me point out that this is not recommended, since the user should have control over the visibility of FactBoxes so your design should always take this into consideration; Having said that, if you for some reason want to control the visibility, here’s how to do it:

void toggleFormPartVisibility(boolean _isVisible = false)
{
    PartList                partList;
    FormRun                 formPart;
    str                     formName;
    int                     counter;    
   
    partList = new PartList(element);
   
    //formName is the name of the form that the factbox is referring to.
    formName = formStr(SomeFormPart);
   
    for(counter = 1; counter <= partList.partCount(); counter++)
    {
        if(partList.getPartById(counter).name() == formName)
        {
            formPart = partList.getPartById(counter);
            formPart.design().visible(_isVisible);
            break;
        }
    }
}

Other properties can also be accessed this way, e.g. if you want to refresh the FormPart’s data source:
formPart.dataSource().reread();
formPart.dataSource().refresh();

This will cause some performance issues due to extra RPC calls, so you should have a good reason to take this approach.

Experiment with the other properties and share how it goes.

2 comments:

  1. Hi, do you accept guest bloggers? I want to share some of my ideas with you. I have a software or tool named Project Management Tools which is ideal in managing your online business. Here's a link if want to take some tour: http://www.projectmanager.com/project-management-software.php. Anyways, if its okay for you to exchange links or contribute content, please its my pleasure to be your partner. Thanks.

    ReplyDelete
  2. The connections that you make early in your career will take you far. After 20 years it is still true for me. This has been true regarding companies I worked for and those I worked with. All you have written is excellent advice.
    online classes

    ReplyDelete