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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Reasoncode Lookup on standard form extension

(0) ShareShare
ReportReport
Posted on by 66

Hi,

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)
    {
        useOffsetAccount=false;
    }
    else
    {
        useOffsetAccount=true;
    }
    useMainAccount = true;
    useLedgerAccount = true;
    offsetacttype=LedgerJournalACType::FixedAssets;
    acttype=LedgerJournalACType::Cust;
    ledgerAccountType = LedgerJournalACType::Ledger;

    ReasonFormTable::reasonCodeLookup(this,offsetacttype,acttype,useMainAccount,useOffsetAccount,ledgerAccountType,useLedgerAccount);
}

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.

ReasonFormTable::reasonCodeLookup(this,offsetacttype,acttype,useMainAccount,useOffsetAccount,ledgerAccountType,useLedgerAccount);

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.

Thanks,

VK 

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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?

  • vicky1234 Profile Picture
    66 on at

    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);
    
    ReasonFormTable::reasonCodeLookup(_control,LedgerJournalACType::FixedAssets,LedgerJournalACType::Cust,true,true,
    LedgerJournalACType::Ledger,true);
    }

    Event handler is working perfectly for me as of now.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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
    66 on at

    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.

    [ExtensionOf(formStr(CustTable))]
    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
            sysTableLookup.performFormLookup();
        }
    }

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

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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...

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans