I understand that the table's data method creates a copy of a record including the system fields. Normally it should generate a new RecID, which is reasonable because otherwise you cannot insert the record in the same table.
Now I'm having a case where the data method is creating a copy which has the same RecId, leading to an error during the insert operation. I'm not sure why this is happening and would appreciate any input on this topic.
What I'm doing:
This is a standard AX method, so why isn't it working?
The data
method of table objects copies all fields including RecId
and other system fields. The insert
methods takes care of the generation of RecId
.
By the above logic your code should not fail due to the RecId
index.
Maybe another unique index is in play?
Most likely you passed a wrong or zero RecId
in the call to the method.
You use two records buffer, this is unnecessary, just change the record key fields and insert:
while select translation
where translation.Category == this.RecId ...
{
translation.Category = _duplicateComponent;
translation.insert();
}