Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Code Optimization in form override lookup method

(0) ShareShare
ReportReport
Posted on by

Hi i'm new to ax and learning new concepts. So I have a piece of code which i have to optimise it.

public void lookup()
{
Query query = new Query();
QueryBuildDataSource qbdsCustInvoiceJour;
QueryBuildRange qbr;

SysTableLookup sysTableLookup = sysTableLookup::newParameters(tableNum(CustInvoiceJour),this);
qbdsCustInvoiceJour = query.addDataSource(tableNum(CustInvoiceJour));
qbdsCustInvoiceJour.addRange(fieldNum(CustInvoiceJour,InvoiceAccount)).value(Customer.valueStr());

sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour,InvoiceAccount));
sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour,CurrencyCode));
sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour,custgroup));
sysTableLookup.addLookupfield(fieldNum(CustInvoiceJour,InvoiceId));

sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}

Is there any way i can shorten the size of the code.

*This post is locked for comments

  • RE: Code Optimization in form override lookup method

    Thank you ! Nikolaos.

  • RE: Code Optimization in form override lookup method

    Thank you! Martin.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: Code Optimization in form override lookup method

    You should remove the unused variable qbr, but otherwise there is not much to do. The code is fine - don't waste time with it. I'm sure you have a plenty of other things that needs refactoring.

    public void lookup()
    {
        Query query = new Query();
        QueryBuildDataSource qbdsCustInvoiceJour = query.addDataSource(tableNum(CustInvoiceJour));
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CustInvoiceJour), this);
        
        qbdsCustInvoiceJour.addRange(fieldNum(CustInvoiceJour,InvoiceAccount)).value(Customer.text());
        
        sysTableLookup.addLookupField(fieldNum(CustInvoiceJour, InvoiceAccount));
        sysTableLookup.addLookupField(fieldNum(CustInvoiceJour, CurrencyCode));
        sysTableLookup.addLookupField(fieldNum(CustInvoiceJour, CustGroup));
        sysTableLookup.addLookupField(fieldNum(CustInvoiceJour, InvoiceId));
        
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }

    By the way, please use the </> button in the rich formatting view to paste source code (as I did above).

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Code Optimization in form override lookup method

    I don't think it can be shortened. Why would you like to do that?

    But one thing to optimize is to move this code in CustInvoiceJour table, and just call it from the lookup method. That way the code can be reused.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans