Thursday, October 4, 2012

AX2012 jumpRef in Sys Operation Framwork


In AX2012, if you have an SSRS report that has parameters and you want to customize the “go to main table functionality” of a parameter, here’s how to do it:
In the UI builder of the report, override the postRun() method:

/// <summary>
///     This method registers the dialog field methods to capture events.
/// </summary>
public void postRun()
{
    Dialog dialogLocal = this.dialog();
    DialogField dialogField;

    super();

     // This method should be called in order to handle events on dialogs.
    dialogLocal.dialogForm().formRun().controlMethodOverload(false);

    dialogField = this.bindInfo().getDialogField(this.dataContractObject(),
        methodstr(CustTableReportContract, parmCustTable));
   
    // Override the default jumpRef to use custTableJumpRef.
    dialogField.registerOverrideMethod(methodstr(FormStringControl, jumpRef),
        methodstr(CustTableReportUIBuilder, custTableJumpRef), this);
}


Add a method custTableJumpRef() to be used in place of the default jumpRef of the control, this can be added to the UI builder class of the report:

/// <summary>
///    Provides go to main table (View Details) functionality.
/// </summary>
public void custTableJumpRef()
{
    MenuFunction    menuFunction;
    Args            args = new Args();
   
    menuFunction = new MenuFunction(menuitemDisplayStr(CustTable), MenuItemType::Display);   
   
    // Pass the record selected in the lookup here.
    args.lookupRecord(CustTable::find('4000'));
   
    // If you don't want to pass any queries to the jumpRef form.
    menuFunction.copyCallerQuery(CopyCallerQuery::No);
   
    // Call the jumpRef form.
    menuFunction.run(args);
}

This can be used to override any number of default methods of control to provide customized functionality e.g. lookup.

The Sys Operation Framework (formerly known as the Business Operation framework, or BOF) also follows the same pattern; so you can use the above example in that as well.

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.