Thursday, September 26, 2013

jumpRef variations

jumpRef method is overriden for enabling the 'View details' feature, when you right click on a field.
If your datasource on a form has relations to multiple tables with the same field, the form may choose the undesired table to reference.

You can do this either on the datasource field or the form control. Once you have overridden the method add code similar to the example below.
    Args    args;
    FormRun  formRun;

    args = new Args(formstr(VendTable));
    formRun = classfactory.formRunClass(args);

Notice the record parameter, it is the actual table record you want to open.

Imagine a situation where you open a form B by clicking a button on form A. The clicked method of the button had the above code. And you want to perform some operation after the form B is closed. You could use the closedOk method of form B and call any method on form A like below.
    if (formRun.closedOk())

Instead of formRun, a more secure and neater approach would be to use the MenuFunction like below. Its secure because it uses the menu item on which we can control access. copyCallerQuery() is optional. In some instances, when you have a grid of a different datasource than the main datasource with no relation to main datasource table, its records wont be populated if you don't use copyCallerQuery.
    menuFunction = new MenuFunction(MenuItemDisplayStr(VendTable), MenuItemType::Display);   

AX also provides two classes, smmUtility and MenuFunction, which provide out of the box methods to achieve above functionality. Some examples picked up from standard AX.

smmUtility: openMenuItemForm and performJumpRef

smmUtility::peformJumpRef(tablenum(smmQuotationReasonGroup), smmQuotationReasonGroup::find(this.text()).RecId);

MenuFunction: runClient
public void jumpRef()
    Args argsProductForm;

    argsProductForm = new Args();


No comments:

Post a Comment