Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Cannot insert record into custom table

Posted on by Microsoft Employee

Hi,

I have created a simple table to store the errors during validation of a file. I am able to insert records in the table when I run it. But when I try to do it through code, nothing happens and I do not get any error either.

Same with the delete, I cannot delete records through code.

I am using simple code as below 

MyTable.INIT; 

MyTable.No := 1;

MyTable.Error := 'Error Occurred';

MyTable.INSERT;

Any idea what the issue might be? Any help will be appreciated.

Thanks,

Aparna

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    Not really. I tried commenting all the code in the trigger except the insert and still no save until I use COMMIT.

    Also, the delete is not working without COMMIT either. If I use the code below by itself, data stays. Only if use COMMIT after this, the data gets deleted. It is very strange and I would like to know why, but for now, I can at least go forward.

    WHILE ErrorsTable.FIND('-') DO        // empty the errors table.

     ErrorsTable.DELETE;

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Cannot insert record into custom table

    May be there is statement for error, such as ERROR('') without any error information to display, which will also rollback the transaction.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    No, I am not. I did not quite understand why I had to use COMMIT. I have never had to do it before.

    The only reason I found out was because I was trying to print a report on this data knowing that it is available within the trigger.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Cannot insert record into custom table

    Aparna,

    Unless you code is generating an error you don't need to use COMMIT, as you mentioned previously you are not getting any errors.

    Are you using TryFunction or Codeunit.RUN ?

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    Hello all,

    The issue is resolved. I had to use the COMMIT function specifically.

    Thank you for all the input.

    Regards,

    Aparna

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    I am not getting any error. Also, I found out that the table is being treated as a temporary table, although I have not set it as temporary. I can use it within the trigger but the data is gone once I get out of it.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Cannot insert record into custom table

    Are you getting any error ? Try adding a MESSAGE BOX after insert and check if you get the message ?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    It is a simple insert code, there are currently no records in the table. When it did not insert any records through my validation routine, so I just tried the code below and it does not do anything. The table variable is not marked as temporary.

    MyTable.INIT;

    MyTable.No := 1;

    MyTable.Error := 'Error Occurred';

    MyTable.INSERT;

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot insert record into custom table

    The code is in the OnPreXMLPort trigger. It is for validation of a file before it is imported as transfer order.

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Cannot insert record into custom table

    Try to send us the complete code, where you have this code and when are you doing it ?

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans