Skip to main content

Notifications

Announcements

No record found.

Supply chain | Supply Chain Management, Commerce
Answered

Copying in Abstract tables - Database insert operation is not allowed on an abstract table.

(1) ShareShare
ReportReport
Posted on by 22
I have three tables. An abstract one, and two others that extend it:

 

PlanLine (with property abstract: yes)

PlanLineTime (extends PlanLine)

PlanLineCounter (extends PlanLine)

 

I am trying to copy a line from PlanLine.

 

So I tried this in a Form where PlanLine is a Data Source:

 

    private void copyPlanLines()
    {
        PlanLine copiedLine;
 
        while select * from copiedLine
        where copiedLine.MaintenancePlan == OriginaRecId.value()
        {
            buf2buf(copiedLine, planLine);
            planLine.MaintenancePlan = maintenancePlan.RecId;
            planLine.insert();
        }
    }

And this 👆 works!

But my Form got a bit bulky so I moved the logic into a class. And there I cannot do this:
 
    private void copyPlanLines()
    {
        PlanLine copiedLine;
 
        while select * from copiedLine
        where copiedLine.MaintenancePlan == fromMaintenancePlan.RecId
        {
            PlanLine newPlanLine;
 
            buf2buf(copiedLine, newPlanLine);
            newPlanLine.MaintenancePlan = newMaintenancePlan.RecId;
            newPlanLine.insert();
        }
    }
 
I get Database insert operation is not allowed on an abstract table.
 
What is the issue? How do I insert new data into an abstract table from a class?
  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    Copying in Abstract tables - Database insert operation is not allowed on an abstract table.
    Maybe you could also do something like this:
    while select copiedLine
        where copiedLine.MaintenancePlan == fromMaintenancePlan.RecId
    {
        if (copiedLine is PlanLineTime)
        {
            ...
        }
        else if (copiedLine is PlanLineCounter)
        {
            ...
        }
    }
    
     
    And by the way, you could improve performance by using a RecordInsertList rather then separate inserts.
  • Karel Cancara Profile Picture
    Karel Cancara 22 on at
    Copying in Abstract tables - Database insert operation is not allowed on an abstract table.
    As @Martin Dráb mentioned, I shouldn't have inserted into the abstract table. 

    I managed to copy all the lines I wanted from the abstract table (PlanLine) into the child tables (PlanLineTime, PlanLineCounter) by writing two separate methods looping through and inserting into both of the child tables separately.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    Copying in Abstract tables - Database insert operation is not allowed on an abstract table.
    Inserting to an abstract table sounds wrong to me. By marking it abstract, you're saying that the table can't be used for storing data; it just contains some common fields and logic to be inherited by child tables, and you should always insert into those non-abstract tables. Do you see it differently?
     
    I got your point that it works in your first code snippet, but maybe you shouldn't be doing it at all.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans