Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Updating a lookup fiel...
Finance forum
Unanswered

Updating a lookup field on the form when related field is updated, but before submitting the changes to DB

Posted on by 30

My main table (named for example MySetupTable) has a field named SetupMainAccount, which is related to the system table MainAccount through its field RecId. The field shows Account Number from the MainAccount table, but the client also wants to see the Account Number value in a separate read-only column in a form grid. I've done it by adding MainAccount table to the form's data sources, along with my main table, and specified the relation between the two data sources. Everything looks fine in there, but when the Account Number is updated in the grid (through a drop-down control), the Account Name is not updated until the record is saved in the database. My client would like to have the Account Name updated as soon as the value is changed on the form. I have tried to achieve this by overriding the modified method of the MainAccount field of the main table data source. And I have tried all of these, both separately and combined:
    MySetupTable_ds.refresh();
    MySetupTable_ds.research(true);
    MainAccount_ds.refresh();
    MainAccount_ds.research(true);
The only method that produced the result that I wanted (updated Main Account Name value right after the Account Number is updated) was MySetupTable_ds.research(true). But the problem with calling this method from the overridden update method is that it not only refreshes the data source, but also submits the changes to the database, which is not a desired behavior I suppose. So my question is - is it possible, and if it is how, to have the lookup field on the form (Account Name in this case) updated based on the selection in the related field (Account Code)?

  • Ascalab Profile Picture
    Ascalab 30 on at
    RE: Updating a lookup field on the form when related field is updated, but before submitting the changes to DB

    Thanks goshoom, I was thinking about that, but then I found an easier and I would say more elegant solution, which didn't require any X++ code. So instead of adding another data source for MainAccount table and using its Name field to be added to the grid's field list, I have added SetupMainAccount from my main table (MySetupTable), and thereafter by setting the Replacement Field Group property of these grid fields to the MainAccount's field groups that show just the Account Number field (this is AutoIdentification group) and the Name field (Name field group). Both these groups exist in the original MainAccount table design, but if some table doesn't have an adequate group, it can be added through a table extension.

  • Martin Dráb Profile Picture
    Martin Dráb 228,625 Most Valuable Professional on at
    RE: Updating a lookup field on the form when related field is updated, but before submitting the changes to DB

    According to your previous thread, this question is about F&O, threfore let me move it to the Dynamics 365 Finance forum.

    Didn't you consider simply finding the name and setting it to the field in modified()?

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans