Friday, 1 June 2018

JumpRef() on unbound control in D365FO


class CGLProcCategoryHierarchyManagementFormEventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(ProcCategoryHierarchyManagement, EcoResCategory), FormDataSourceEventType::Initialized)]
    public static void EcoResCategory_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormRun           formRun = sender.formRun();
        EcoResCategory    ecoResCategory = sender.cursor();
        FormStringControl budgetManager  = formRun.control(formRun.controlId('CGLBudgetManager'));
        var overrides = CGLProcCategoryHierarchyManagementFormEventHandler::construct();
       
        budgetManager.registerOverrideMethod(methodStr(FormStringControl, jumpRef),    methodStr(CGLProcCategoryHierarchyManagementFormEventHandler, budgetManager_OnJumpRef), overrides);
    }

    public static CGLProcCategoryHierarchyManagementFormEventHandler construct()
    {
        return new CGLProcCategoryHierarchyManagementFormEventHandler();
    }

    public void budgetManager_OnJumpRef(FormStringControl _targetField)
    {
        Args            args;
        MenuFunction    menuFunction;
        HcmWorker       hcmWorker;
        DirPerson       person;
        DirPartyTable   partyTable;
   
        if (_targetField.valueStr() != "")
        {
            menuFunction = new MenuFunction(menuitemDisplayStr("hcmWorker"), MenuItemType::Display);
            args = new Args(menuFunction.object());
          
            select hcmWorker
                join recid from person
                    where hcmWorker.Person == person.RecId
                join recid from partyTable
                    where person.recid == partyTable.recid
                        &&partyTable.Name == _targetField.valueStr();

            if (hcmWorker.RecId != 0)
            {
                args.record(hcmWorker);
                args.lookupRecord(hcmWorker);
                menuFunction.run(args);
            }
          
        }
    }

}

No comments:

Post a Comment