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, ...
Answered

Buf2Buf error in tables with Inheritance

(0) ShareShare
ReportReport
Posted on by 157

Hello to everyone. 

I have 2 tables. TableA and TableB. TableB use inheritance and extends TableA

It seems that everything works fine but I have one weird issue. 

I use a method like this: 

public void createElement(TableA _parentRecord, TableA _copyRecord)
{
    TableA newRecord;

    if (_copyRecord)
    {
        buf2Buf(_copyRecord, newRecord);
        //Other Code
    }
    else
    {
        buf2Buf(_parentRecord, newRecord);
        //Other Code
    }


I always recieve an error that inform that  "The field with ID '36' does not exist in table 'TableA'

I entered to the debugger inside the buf2Buf() to understand why this happens and I saw that the _from buffer is TableB and not TableA

even if I tried to cast again the buffers to TableA , when it goes inside the buf2buf method the type is TableB. 

Does anyone know why this happens?

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

    Casting an object to a parent type indeed doesn't change its type. It's still the same object as before.

    What is your intention here? Do you want to ignore all fields define in TableB? If not, your attempt to convert TableB to TableA wouldn't meet your requirements, even if it worked.

    In short, it seems that buf2buf() doesn't support what you want. Can't you achieve your goal with data() method?

  • SGbron Profile Picture
    157 on at

    Hello Martin.

    Exactly, I want to ignore all fields that are coming from TableB. Becasue I received this error with the fieldId.

    And also I dont need them.

    .TableA does contain all the fields that I want. So what i am trying to do is to copy one record and I jsut want to modify some fields values after. Because there are many fields (almost 90%) that will remain the same.

    .data it was the first thing that I did but it didn't anything from values from the _parentRecord.

    I thought that this is becasue microsoft recomends on inheritance to use buf2buf instead of data.

    learn.microsoft.com/.../dynamics.ax.application.xrecord.data

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

    I don't think you'll get it working when using two different types (TableA and TableB). But if you're interested just with fields from the parent table, you could select its buffer directly.

    You can see an example below. I changed the types to DirPartyTable and DirPerson, to be able to test the code.

    void run()
    {
        DirPerson person;
        select firstOnly person;
    
        this.createElement(person);
    }
    
    public void createElement(DirPartyTable _parentRecord)
    {
        DirPartyTable input;
    
        if (_parentRecord.TableId == tableNum(DirPartyTable))
        {
            input = _parentRecord;
        }
        else
        {
            select firstonly input
                where input.RecId == _parentRecord.RecId;
        }
    
        DirPartyTable newRecord;
        buf2Buf(input, newRecord);
        info(newRecord.Name);
    }

  • SGbron Profile Picture
    157 on at

    Exactly

    it was solved with just a find method.

    TableA parent = TableA::findRecId(_parentRecord.RecId);
    
    buf2Buf(parent, newElement);


    And now the returned type of the Object is TableA instead of TableB

    The thing that i dont understand is how it is posible to give in the method a TableA record from the cursor() position in the form and inside the method that record is a TableB record. 

    Anyway the problem is solved. 

    Thank you Martin

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

    I guess you mean that the type of the data source is TableA, but it doesn't necessarily mean that the type of the record is TableA too. F&O supports polymorphism in forms.

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
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans