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, ...
Suggested Answer

Best practices when initializing datasources

(0) ShareShare
ReportReport
Posted on by 87
Hello,
 
This is a question about best practices in reference to the initialization of datasources in a form. In my case, I have made a form consisting of 3 datasources:
- datasource_1
- datasource_2
- datasource_3
 
The datasource_2 and datasource_3 have datasource_1 as Join Source. After making several tests, I have seen that in the run() of the form, after the super(), the form only has initialized the datasource_1. When datasource_2 and 3 have Link Type: delayed, their record is loaded in its active() method. On the other hand, if the Link Type is active, their record is loaded in the active() of datasource_1.
 
So far so good, now let's say that datasource_3 has no record related to datasource_1, i.e. datasource_3 is blank. In this case, I want to initialize this record with information from datasource_2.
 
There are several ways to solve the problem. For example, check in the active() or executeQuery() if there is a datasource_3 record, and initialize otherwise. Or even use initValue() and initialize the fields directly from the datasource_2 table (using find method), instead of datasource_2 (because datasource_2 is not loaded yet).
 
However, I am not sure which solution is considered best practice. In my opinion, the initValue() is the cleanest. I have seen in other forms that the active() is used a lot, but I think it leads to unnecessary overhead, since the active() is called quite often.
 
What do you think?
 
 
Thanks in advance,

Eisenberk.
 
I have the same question (0)
  • Suggested answer
    Kevin Xia Profile Picture
    Microsoft Employee on at
    Hi,
    The best practice in your case would be to use the initValue() method to initialize the record in datasource_3 from datasource_2 directly. This approach can help you ensure clean and efficient code, avoiding unnecessary overhead. Additionally, checking in the active() or executeQuery() if datasource_3 has a record and initializing it when there isn't one is also a reasonable solution.
    Best regards,
    Kevin
  • André Arnaud de Calavon Profile Picture
    301,194 Super User 2025 Season 2 on at
    Hi Eisenberk,
     
    If you want to initialize values for a new record, then active() is not the correct method. Like mentioned by Kevin and yourself the initValue() method it the appropriate one. That method is triggered when creating a new record.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans