Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

How to add a new record in a related table from a form

(0) ShareShare
ReportReport
Posted on by 30

Hello, 

I'm working in AX 2012 R3.

I'm updating the BatchJob Form.

I created a second table to add more fields to the BatchJob table.

The second table relates to BatchJob with relationshiptype = Composition.

In the form I have 2 datasources one for BatchJob and another for BatchJob_Extend table.

The BatchJob_Extend datasource has Batchjob as join datasource of type OuterJoin.

I then modified the grid to show fields from the new Batchjob_Extend table.

When I tried to modify a field in the new table and I move out of the record I get an error: "Field 'Reference' must be filled in.

If I play around with the join source settings I can get the records to be inserted but then the form doesn't load the data properly for the new fields.

Any help would be appreciated.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: How to add a new record in a related table from a form

    Hi Carlo,

    I think it will be best for you to use table extension framework for this. Please check this post for an example of how to do this.

    You can also check tables SalesLine and SalesLine_IN which have been designed in the same way.

  • Carlo T Profile Picture
    Carlo T 30 on at
    RE: How to add a new record in a related table from a form

    Hi again.

    It's there a way to stop the form to try to create the new record in BatchJob_Extend when I create a new record in BatchJob?

    When I create the record I still have the same problem of missing reference but the BatchJob.RecId is still empty

  • Carlo T Profile Picture
    Carlo T 30 on at
    RE: How to add a new record in a related table from a form

    Thank you GunJan.

    I had to modify your suggestion and I ended up overwriting the ValidateWrite method in the datasource you recommend. I guess the sequence of events on the form was validating before doing the actual writing.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: How to add a new record in a related table from a form

    Hi Carlo,

    You can override write method in the Batchjob_Extend datasource and populate the field using which you have linked it to BatchJob table.

    public void write()
    {
        if (!batchJob_Extend.BatchJob)
        {
            batchJob_Extend.BatchJob = batchJob.RecId; 
        }
        
        super();
    }

    This way the reference field will be populated in the 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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans