Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Unanswered

X++ Saving optional record in form with data source change group set to None

Posted on by
Dear all,
 
I have an issue saving an optional record in a form. The form displays a list of records from a /Books/ table. Each /Book/ record may have one or more translations. On the form, users have the possibility to enter the default translation (set to the system language, i.e., en-US).
 
Data model:
 
//
 
/Book/ is the main data source on the form; /BookTranslation/ is the optional data source. It is joined with an outer join to the /Book/ data source. The init() method has been overridden on the /BookTranslation/ data source, to ensure only 1 record is selected.
 
//
 
//
 
//
 
When I try to save a record, the /Book/ field on the /BookTranslation/ data source is left blank, causing the save operation to fail.
 
//

The form has /Data Source Change Group/ set to /None/, which apparently causes this behavior. Changing this property to /ImplicitInnerOuter/ would solve the issue, but, unfortunately, this is not a viable solution, as the actual scenario is an extension of a standard form (this is a simplified example).
 
I have tried to override the write() method on the data sources, but this did not help. As per documentation, I was expecting that each data source got saved in its own transaction, following the method call sequence below:
  1. Book.validateWrite()
  2. Book.write()
  3. BookTranslation.validateWrite()
  4. BookTranslation.write()
Adding code to the Book.write() method would allow me to set up the needed values in the /BookTranslation/ record. However, the methods are actually called in the following order:
  1. Book.validateWrite()
  2. BookTranslation.validateWrite()
  3. Book.write()
  4. BookTranslation.write()
This would require to perform this initialization in the validateWrite() method, which seems the wrong place to me. Additionally, since validateWrite() is called before write(), i.e., before the record is saved to the database, I do not have the possibility to read the Book's /RecId/ (in the actual scenario, /BookTranslation/ is linked to /Book/ via RecId, not via ISBN).
 
Does anybody have suggestions on how to solve this issue? I would be grateful for your feedback.
 
Best regards,
Daniel

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans