Thursday, August 10, 2023

JumpRef in form extension X++

class PurchTableForm_EventHandler
{
    /// <summary>
    /// JumpRef mthod overrride for form control
    /// </summary>
    /// <param name = "sender"></param>
    /// <param name = "e"></param>
    [FormEventHandler(formStr(PurchTable), FormEventType::PostRun),SuppressBPWarning('BPParameterNotUsed', 'Parameter required')]
    public static void PurchTable_OnPostRun(xFormRun sender, FormEventArgs e)
    {
        FormStringControl   control = sender.design().controlName(formControlStr(PurchTable, TransferOrderId));
        control.registerOverrideMethod(methodStr(FormStringControl, jumpRef), methodStr(PurchTableForm_Extension, jumpRef), sender);
    }

}

/// <summary>
/// Extension for PurchTable form
/// </summary>
[ExtensionOf(formstr(PurchTable))]
final class PurchTableForm_Extension
{
    /// <summary>
    /// JumpRef override method
    /// </summary>
    /// <param name = "_formControl">form controlId</param>
    public void jumpRef(FormControl _formControl)
    {
        MenuFunction	menuFunction;
        Args        	args = new Args();
        PurchTable      purchTable  =_formControl.formRun().dataSource(formDataSourceStr(PurchTable,PurchTable)).cursor() as PurchTable;

        if(purchTable.TransferOrderId)
        {
            InventTransferTable  InventTransferTable = InventTransferTable::find(purchTable.TransferOrderId);

            args.record(InventTransferTable);
            args.lookupRecord(InventTransferTable);

            menuFunction = new MenuFunction(menuitemDisplayStr(InventTransferOrder), MenuItemType::Display);

            menuFunction.run(args);
        }
    }

}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8