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 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.
Exactly
it was solved with just a find method.
TableA parent = TableA::findRecId(_parentRecord.RecId); buf2Buf(parent, newElement);
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); }
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
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?
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156