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 :
Microsoft Dynamics AX (Archived)

Display method performance issue

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

i use two display methods and i experienced a strange behavior.

I want to extend the form part EcoResProductPerCompanyPreviewPart. We want to display the current quantity in open sales lines:

ProdListPage-_0E202A20_.png

My first approach was to define a display method in the form because there is no datasource and no specific relation.

DisplayMethodInForm_0E202A20_.png

Because this approach was very slow i tried another one. I added two datasources without any links and queries and moved the display methods into the datasources.

DisplayMethodInDS-_0E202A20_.png

The code in the display methods is exactly the same but the second approach is much faster. Why??

Any ideas on this?

Regards

Nils

*This post is locked for comments

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

    You could find the answer by measuring what consumes all the time in the former case.

    If you want some advice from us, please show us what's inside your methods.

  • Community Member Profile Picture
    on at
    I wonder why the same code behaves different in two cases.

    public display Qty getBackorderQty() { SalesLine localSalesLine; InventTable argsRecord; argsRecord = element.args().record(); select sum(RemainSalesPhysical) from localSalesLine where localSalesLine.ItemId == argsRecord.ItemId && localSalesLine.SalesStatus == SalesStatus::Backorder; return localSalesLine.RemainSalesPhysical; }

    public display InventQtyAvailPhysical getAvailPhysical()
    {
        InventSum localInventSum;
        InventTable argsRecord;
    
        argsRecord = element.args().record();
    
        select sum(AvailPhysical) from localInventSum
            where localInventSum.ItemId == argsRecord.ItemId;
    
        return localInventSum.AvailPhysical;
    }
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Maybe the code executes exactly the same, but it differs in how many times you call it (depending on where you use the display method).

    Nevertheless note that performance problems are rarely solved by guessing; measuring what takes time is a much more successful approach.

  • Verified answer
    KyleLeBarre Profile Picture
    747 on at

    Form level display methods get called a ridiculous amount of times for no reason, in my experience. They also can't be cached.  

    I don't see a reason why you couldn't add these display methods to the InventTable (the actual table object, not the form datasource). You could decorate it with [SysClientCacheDataMethodAttribute] to have the form automatically cache it, too.

  • Community Member Profile Picture
    on at

    Thank you! I will try that tomorrow.

    Regards

    Nils

  • Community Member Profile Picture
    on at

    Works great!

    I moved the display methods into the InventTable so there is no need to keep SalesLine and InventSum datasources in the form. Works much faster than the Form-display variant.

    Thank you!

    Regards Nils

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

    Caching is absolutely critical with display methods. In your case, it's enough to run your code only once (unless element.args().record() changes), while uncached display methods would run your queries again and again on every screen refresh for absolutely no reason.

    You can see that you could calculate the value in linkActive() and then just display it in the form (as unbound fields or using a form-based display methods). You have many options, but in either case you must ensure yourself that you don't do more DB calls from client than necessary.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans