Fetch FormControl and value of different type in Event Handler of D365 Operations

Introduction:

In this blog article, we will see how we can fetch Form Control and its value which is of different datatype in EventHandler in D365 Operations

Scenario:

I am working on Global Address Book functionality for checking Duplicate values for PartyID (String), Tax Id (CheckBox) and Tax Id Type (ComboBox). I am using Event Handler of form method to enable a button based on value of above three fields.

Steps:

Create Event Handler with below code:

[PostHandlerFor(formStr(DirPartyCheckDuplicate), formMethodStr(DirPartyCheckDuplicate, enableSearch))]
    public static void DirPartyCheckDuplicate_Post_enableSearch(XppPrePostArgs args)
    {
        FormRun formRun = args.getThis() as FormRun;
        FormCheckBoxControl TaxId       = formRun.design(0).controlName("TaxId") as FormCheckBoxControl;
        FormStringControl PartyNumber   = formRun.design(0).controlName("DirPartyTable_PartyNumber") as FormStringControl;
        FormComboBoxControl TaxIdType   = formRun.design(0).controlName("TaxIdType") as FormComboBoxControl;
        FormControl searchBtn           = formRun.design(0).controlName("searchBtn");
        

        if(TaxId.value() ||
            PartyNumber.valueStr() ||
            TaxIdType.valueStr())
        {
            searchBtn.enabled(true);
        }
        else
        {
            searchBtn.enabled(false);
        }
        
    }

Share Story :