Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

I want Skip or Ignore Inserting record which one have a Error while inserting multiple records.

Posted on by 62

Scenario: I have 2 table (custom Invoice and standard Purchase Header).
I am inserting multiple records using codeunit from "Custom Invoice" to " Purchase Header".
I want to put logic or validation that if any record facing error while inserting multiple records it should store value of error for that record and let it insert the next records.

Categories:
  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,025 Moderator on at
    RE: I want Skip or Ignore Inserting record which one have a Error while inserting multiple records.

    Hi,

    To achieve this you can do the following

    1. Create a functions in some other objects to Loop through your table to get the records

     Function()

    {

      table repeat

      codeunit.setparameter(table);

      if not codeunit.run() then

        logyourerror here in some other table.

     until table.next = 0;

    }

    2. Now as you can see we are calling Codeunit.run in if condition and before that we are setting up our table paramter

    codeunit 

    trigger OnRun ()

    begin

      recordingtransferfromhere;

    end;

    setparameter(table:record)

    begin

      table2 := table;

    end;

    local function recordingtransferfromhere()

    var

    destTable:record;

    begin

      destTable.transferfields(table2);

       destTable.insert();

    end;

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 70,124 Super User 2024 Season 2 on at
    RE: I want Skip or Ignore Inserting record which one have a Error while inserting multiple records.

    Hi, hope the following can give you some hints.

    Handling Errors using Try Methods:

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-handling-errors-using-try-methods

    https://yzhums.com/19630/

    Collecting Errors:

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-error-collection

    https://www.youtube.com/watch?v=8_ltR1ceTKA

    Thanks.

    ZHU

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans