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)

Multiple method calls

(0) ShareShare
ReportReport
Posted on by 230

Hi All!


I have a little strange situation. I have a form with one table (TEST) with 6 records. In DS of that form (TEST_ds) I added init with lines

<code>

  super();
 this.query().dataSourceName('TEST').addRange(fieldnum(TEST,id)).value(queryvalue('2'));

</code>

Then I added also to this DS a method "test" with
<code>

display str test()
{
print "test";
return "test";
}

</code>

Then I added a field with data source TEST and method test to grid.

After opening a form I get exactly one record - very good, but "test" method is called 4 times.

Is it a bug on old Axapta version or I can change it to method "test" run only once?

I am asking because I have other, bigger form, where one of column is calculated for one record over 3 sec. On that form once record is shown finally but method is calculated multiple, 16 times for the same itemid, but  others value of joining table records. After analyses I discover above and do very basic test describe above also what confirm that generating of record doesn't take 3 sec, but 16*3.

Thanks for your suggestions!

*This post is locked for comments

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

    The method is called every time when a value needs to be displayed, therefore every redraw can execute the method (for each displayed record). Nevertheless values from display methods can be cached.

    Or, if the display method depends on something repeated for several records (e.g. your ItemId repeated for 16 records), you can use a local cache. You'll calculate the value once and cache it, e.g. in a form variable or in global cache. For all subsequent calls with identical parameters, you'll read the value from cache instead of calculating it again.

    The goal is not limiting numbers of calls to other tiers (AOS and database), not necessarily number of all method calls. Method calls on the same tier are relatively cheap, calls to other machines over network are relatively very expensive.

  • PiotrDev Profile Picture
    230 on at

    Many thanks for that, but it is a little strange for me because I didn't know that this method will call a few times. Ok., but it is a old code of somebody where method is quite big and needed. I don't want to change it but I wonder if is any chance to call it only once for showing in grid row? For example, is it possible to run once a method and return value of field after grid is load and show final list of rows? In above example for row with id =2 I want run once a method to return test value for "col2" field.

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

    Please follow the aforementioned link about display method cache.

  • PiotrDev Profile Picture
    230 on at

    There is "Only table methods that have the display or edit keyword can be cached. Methods that are written on the form or the form data source cannot be cached. ". I have this method on the data source table of form, so I think, Ii can't be cached.

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

    Aha. So you'll have to change your mind about not changing the method, if you want to make any difference.

  • PiotrDev Profile Picture
    230 on at

    Ok, thank you for you help.

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

    If your question has been answered, please mark it as such.

  • Verified answer
    PiotrDev Profile Picture
    230 on at

    Hi All!

    The correct answer in this situation is every time checking some values of record before we calling a huge code in a method, I mean about use if statements and excluding multiple the same records, and also use some temp variable - it's not perfect solution but it's tricky and work quite well. For above example I could call method not 4 times, but only once. For my real problem  where I have a few join tables this way I could minimize calling method from 139 to 14, and time from over 356s to 34s for my example.

    Good luck!

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