x++dynamics-365dynamics-365-operations

Two Lookups in my SysOperation UiBuilder Error


When i click my Sa_Type field that is a base enum with Vendor and Customer i want it to fill my second field called combo with all the customer or all the vendors, but this way im receiving the error

RegisterOverrideMethod was called twice for the same object for method 'lookup'. You can only override a method once per instance sysoperations

I m overriding a modify in order to know when im clicking for vendor or customer. Any solutions ?

public class AdjustmentUiBuilder extends SysOperationAutomaticUIBuilder
    {
        DialogField type;
        DialogField combo;
        
        
        public void build()
        {
            super();
    
            type = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(AdjustmentSysContract, parmType));
            combo = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(AdjustmentSysContract, parmCombo));
            
            this.modifyDialogFields();
        }
    
        public void postRun()
        {
            type.registerOverrideMethod(methodStr(FormComboBoxControl, modified), methodStr(AdjustmentUiBuilder, moduleCustVend_modified), this);
        }
    
        private void lookupCustAccount(FormStringControl _formStringControl)
        {
            Query query = new Query();
            QueryBuildDataSource qbds;
            SysTableLookup sysTableLookup;
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), _formStringControl);
                
            qbds = query.addDataSource(tableNum(custTable));
    
            sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum), true);
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
        }
    
        private void lookupVendor(FormStringControl _formStringControl)
        {
            Query query = new Query();
            QueryBuildDataSource qbds;
            SysTableLookup sysTableLookup;
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), _formStringControl);
                
            qbds = query.addDataSource(tableNum(vendTable));
    
            sysTableLookup.addLookupfield(fieldNum(VendTable, AccountNum), true);
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
        }
    
        private boolean moduleCustVend_modified(FormComboBoxControl _control)
        {
            this.modifyDialogFields();
    
            return _control.modified();
        }
    
        private void modifyDialogFields()
        {
            if(type.value() == Sa_Type::Customer)
            {         
                    combo.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(AdjustmentUiBuilder, lookupCustAccount), this);
            }
            else
            {
                    combo.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(AdjustmentUiBuilder, lookupVendor), this);
            }
        }

Solution

  • So i was thinking this wrong, and with the old code i was doing two overrides to the same dialog. This is the solution i got to fill my lookups.

    public void postRun()
        {
           
            account.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(AdjustmentUiBuilder, lookupAccount), this);
            item.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(AdjustmentUiBuilder, lookupAccountItem), this);
            reason.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(AdjustmentUiBuilder, lookupReason), this);
        }
    
        private void lookupAccount(FormStringControl _formStringControl)
        {
            if(type.value() == Sa_Type::Customer)
            {
                Query query = new Query();
                QueryBuildDataSource qbds;
                SysTableLookup sysTableLookup;
                QueryBuildRange         queryBuildRange;
                sysTableLookup = SysTableLookup::newParameters(tableNum(CustTable), _formStringControl);
                
                qbds = query.addDataSource(tableNum(custTable));
    
                sysTableLookup.addLookupfield(fieldNum(CustTable, AccountNum), true);
    
                sysTableLookup.parmQuery(query);
                sysTableLookup.performFormLookup();
            }
            else
            {
                Query query = new Query();
                QueryBuildDataSource qbds;
                SysTableLookup sysTableLookup;
    
                sysTableLookup = SysTableLookup::newParameters(tableNum(VendTable), _formStringControl);
                
                qbds = query.addDataSource(tableNum(vendTable));
    
                sysTableLookup.addLookupfield(fieldNum(VendTable, AccountNum), true);
                sysTableLookup.parmQuery(query);
                sysTableLookup.performFormLookup();
            }
        }