Skip to main content



No record found.

Dynamics 365 Community / Forums / Finance forum / Reasoncode Lookup on s...
Finance forum

Reasoncode Lookup on standard form extension

Posted on by 462


I have a requirement to show a lookup of a custom field on a std form.

I have added the field in the custom form however the lookup shows as per the EDT properties of the field.

But I have below requirement

Form Name : CustFreeInvoice Add a reason code field which should show the same lookup as what is being shown in the form with edit method "editReasonCode" in the form "CustFreeInvoice ".

I need to add this field at the header level. Now I see that there is below the code written for the lookup field.

public void lookup()
    LedgerJournalACType offsetacttype;
    LedgerJournalACType acttype;
    LedgerJournalACType ledgerAccountType;
    boolean useLedgerAccount;
    boolean useOffsetAccount;
    boolean useMainAccount;

    if (!custInvoiceLine.AssetId)
    useMainAccount = true;
    useLedgerAccount = true;
    ledgerAccountType = LedgerJournalACType::Ledger;


The thing that  I would like to understand is how do I manage the same thing in the extension handler code for the lookup of the custom field being added at the header level.

Majorly I want to understand how extension/handler classes for lookup are being used to call the below methods like.


I know the rest part and I can even replicate the logic in the event handler however i am curious to know if we can just use the same Table lookup method the way we call lookup method from multiple sources.



  • Martin Dráb Profile Picture
    Martin Dráb 225,610 Super User on at
    RE: Reasoncode Lookup on standard form extension

    Yes, if you override a method of a particular form control, it applies to this one control only.

    If you want to change the behaviour of all controls bound to a particular data source field, override lookup() method of the field.

    custTable_ds.object(fieldNum(CustTable, CustGroup).registerOverrideMethod...

  • vicky1234 Profile Picture
    vicky1234 462 on at
    RE: Reasoncode Lookup on standard form extension

    hi Martin,

    Thanks again for the explanation.

    I think in the below code considering the example of the code, only the "posting_Custgroup" lookup will have the lookup overriden however if a user adds the same field by personalization in the grid then it will again call the standard lookup method. and show all the values.

    final class TutorialCustTable_Form_Extension
        public void init()
            next init();
            Posting_CustGroup.registerOverrideMethod(methodStr(FormDataObject, lookup), formMethodStr(CustTable, overridenCustGroupLookup));
        public void overridenCustGroupLookup(FormStringControl _formControl)
            SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(CustGroup), _formControl);
            // Add the lookup columns
            sysTableLookup.addLookupfield(fieldNum(CustGroup, CustGroup));
            sysTableLookup.addLookupfield(fieldNum(CustGroup, Name));
            sysTableLookup.addLookupfield(fieldNum(CustGroup, PaymTermId));
            // Run the lookup

    Or is it that I have not yet understood your solution properly ?

  • Martin Dráb Profile Picture
    Martin Dráb 225,610 Super User on at
    RE: Reasoncode Lookup on standard form extension

    You don't need to have multiple event handler methods. You can write a single method and associate it with several events (by decorating it with multiple event handler attributes).

    Regarding your CoC code, I think the problem is that next lookup() still calls the standard lookup, and you aren't allowed to skip the next call. A workaround is using registerOverrideMethod(). For example, look at How To Override An Existing Lookup Method: Chain Of Command.

  • vicky1234 Profile Picture
    vicky1234 462 on at
    RE: Reasoncode Lookup on standard form extension

    Hi Martin,

    thanks a lot for quick reply.

    What I want to understand is that even after the COC it shows all the records however if I write a eventhandler it gives me correct output with filteration.

    So in case the same field is being used multiple times n the form then i I will have to write the eventhandler multiple times, however If i just write it at datasource field level that will work all the times the field is being used in the form.

    Can you please help me if my understanding is correct and what's wrong with the below code.

    [ExtensionOf(formDataFieldStr(CustFreeInvoice, CustInvoiceTable, CustomReason))]
    final class HS_CustFreeInvoice_CustomReason_Extension
    public void lookup(FormControl _control,str _filter)
    next lookup(_control,_filter);

    Event handler is working perfectly for me as of now.

  • Martin Dráb Profile Picture
    Martin Dráb 225,610 Super User on at
    RE: Reasoncode Lookup on standard form extension

    Hmm, I'm not sure what you want to hear. Are you saying that you neither know how to override lookup() method by CoC not how to create an event handler method? Or do you have a more specific question?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,995 Super User

Martin Dráb Profile Picture

Martin Dráb 225,610 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans