web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Override form data source field lookup - LedgerJournalTransCustPaym

(0) ShareShare
ReportReport
Posted on by 120

Hello everyone,


How can I override the lookup method for MarkedInvoice data source field in LedgerJournalTransCustPaym(Form)? I tried this approach but it won't allow me to replicate the lookup method in my ExrensionOverrideClass

Goal: Trying to change the line
        args = new Args(formStr(CustOpenInvoicesLookup));
and insert my own form like args = new Args(formStr(CustOpenInvoicesLookupCustom));

[DataField]
class MarkedInvoice 
{
...
...
    //
    // Displays a custom lookup form that provides the user with the means of selecting
    // a MarkedInvoice record filtered by the AccountNum (customer) field.
    //
    public void lookup(FormControl _formControl, str _filterStr)
    {
        FormRun formRun;
        Args args;
        args = new Args(formStr(CustOpenInvoicesLookup));
        args.record(ledgerJournalTrans);
        args.caller(element);
        args.lookupValue(ledgerJournalTrans.MarkedInvoice);

        if (_filterStr != '')
        {
            args.parm(_filterStr);
        }

        formRun = ClassFactory::formRunClassOnClient(args);
        formRun.init();

        this.performFormLookup(formRun, _formControl);
    }

...
...
}


Screenshots below are from my ExtensionOverrideClass

pastedimage1620084546761v1.png

pastedimage1620084566817v2.png
pastedimage1620084615635v3.png

Thanks everyone

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at
    RE: Override form data source field lookup - LedgerJournalTransCustPaym

    Hi xppdev,

    Where did you create your new lookup method.

    How did you pass the parameter in the registerOverrideMethod() method?

  • xppdev Profile Picture
    120 on at
    RE: Override form data source field lookup - LedgerJournalTransCustPaym

    Hi Will, here's my class

    class LedgerJournalTransCustPaymCopyExtensionOverrides
    {
        protected void new()
        {
        }
    
    
        public static LedgerJournalTransCustPaymCopyExtensionOverrides construct()
        {
            return new LedgerJournalTransCustPaymCopyExtensionOverrides();
        }
        
        public void lookup(FormControl _formControl, str _filterStr)
        {
            FormRun formRun;
            Args args;
            //Planning to change the CustOpenInvoicesLookup to my own form
            args = new Args(formStr(CustOpenInvoicesLookup));
            ///
            args.record(ledgerJournalTrans);
            args.caller(element);
            args.lookupValue(ledgerJournalTrans.MarkedInvoice);
    
            if (_filterStr != '')
            {
                args.parm(_filterStr);
            }
    
            formRun = ClassFactory::formRunClassOnClient(args);
            formRun.init();
    
            this.performFormLookup(formRun, _formControl);
        }
    }



    My Event handler class

    class LedgerJournalTransCustPaymCopyEventHandler
    {
        
        /// 
        ///
        /// 
        /// 
        /// 
        [FormDataSourceEventHandler(formDataSourceStr(LedgerJournalTransCustPaym, LedgerJournalTrans), FormDataSourceEventType::Initialized)]
        public static void LedgerJournalTrans_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
        {
            Info("Custom lookup");
            var overrides = LedgerJournalTransCustPaymCopyExtensionOverrides::construct();
    
            sender.object(fieldNum(LedgerJournalTrans, MarkedInvoice)).registerOverrideMethod(methodStr(FormDataObject, lookup),
                methodStr(LedgerJournalTransCustPaymCopyExtensionOverrides, lookup), overrides);
        }
    
    }



    Thank you

  • Verified answer
    Martin Dráb Profile Picture
    236,503 Most Valuable Professional on at
    RE: Override form data source field lookup - LedgerJournalTransCustPaym

    It seems that you don't know how to get references to ledgerJournalTrans, element and this variables.

    this is trivial - simply use _formControl instead.

    element represents the current FormRun object. You can get it by calling _formControl.formRun().

    If the form control is bound to ledgerJournalTrans data source, you can get a reference to it by calling _formControl.dataSourceObject(). Then call its cursor() method to get the current table buffer.

  • Verified answer
    WillWU Profile Picture
    22,361 on at
    RE: Override form data source field lookup - LedgerJournalTransCustPaym

    Hi partner,

    The ledgerJournalTrans is not instantiated in the class, please refer to Martin's method to instantiate the variable.

  • xppdev Profile Picture
    120 on at
    RE: Override form data source field lookup - LedgerJournalTransCustPaym

    Thanks Martin, was able to get it using the code below

    FormRun formRun = _formControl.formRun();
    FormDataSource ledgerJournalTransDS = formRun.dataSource(formDataSourceStr(LedgerJournalTransCustPaym, LedgerJournalTrans));
    FormDataObject markedInvoice = ledgerJournalTransDS.object(fieldNum(LedgerJournalTrans, MarkedInvoice));
    LedgerJournalTrans ledgerJournalTrans = ledgerJournalTransDS.cursor();
    Args args;
    args = new Args(formStr(CustOpenInvoicesLookupCopy));
    args.record(ledgerJournalTrans);
    args.caller(formRun);
    args.lookupValue(ledgerJournalTrans.MarkedInvoice);
    
    if (markedInvoice.getValue() != '')
    {
        args.parm(markedInvoice.getValue() );
    }
    
    
    FormRun formRun2 = _formControl.formRun();
    formRun2 = ClassFactory::formRunClassOnClient(args);
    formRun2.init();
    
    markedInvoice.performFormLookup(formRun2, _formControl);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 1,882

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 794 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 525 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans