web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Field Validation: Skip errors

(1) ShareShare
ReportReport
Posted on by 395
Hi all, 
 
We have the below custom table created in Business Central: 
 
 
We would like to create a background process (via job queue) that loops through the payment lines and for each record, create a cash receipt journal. High evel code we have uptill now is as per below; 
 
procedure ProcessPayments()
    var
        PaymentLine: Record PaymentLine;
        CashRcptJnl: Record "Gen. Journal Line";
    begin
        if PaymentLine.Findset() then begin
            repeat
            begin
                CashRcptJnl.Reset();
                CashRcptJnl.Init();
                CashRcptJnl.Validate("Journal Template Name", 'RECEIPTS');
                CashRcptJnl.Validate("Journal Batch Name", 'CASHRCPT');
                CashRcptJnl.Validate("Posting Date", Today());
                CashRcptJnl.Validate("Account Type", CashRcptJnl."Account Type"::Customer);
                CashRcptJnl.Validate("Account No.", PaymentLine.CustomerNo);
                CashRcptJnl.Validate(Amount, PaymentLine.Amount);
                CashRcptJnl.Validate("Currency Code", PaymentLine.CurrencyCode);
                CashRcptJnl.Validate("Bal. Account Type", CashRcptJnl."Bal. Account Type"::"Bank Account");
                CashRcptJnl.Validate("Bal. Account No.", PaymentLine.BankNo);
                if CashRcptJnl.Insert() then begin
                    PaymentLine.Validate(Processed, true);
                    PaymentLine.modify(true);
                end;
            end;
            until (PaymentLine.Next = 0);
        end
    end;
 
We would like that if one of the payment line fails validation on any o the fields, the process does not stop or issues an error - we would like it to proceed to the next payment line (we will be holding a seperate custom table as a log and we will keep errors there). At the moment it is failing on one of the validate lines (in one particular example, USD did not exist as currency and therefore it returned an error that it does not exist). 
 
How can we run all the validates without stopping the process in case one of the validations is not successful? We do not want to use value assignments (example CashRcptJnl."Currency Code" := PaymentLine.CurrencyCode) because we still want the validation to run... just not output any error that stops the process. 
 
Is there a way how we can do this, please? 
 
Any help is appreciated. 
Thanks in advance! 
 
 
I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,763 Super User 2025 Season 2 on at
    Hi, As far as I know there is no easy way. You could try the Try Method, but I don't think this will skip the standard validate error.
    Dynamics 365 Business Central: How to use Try methods/functions (TryFunction Attribute)
     
    So, like the standard, you should check these problems in your code before executing the operation. If there are any problems, do not execute it, or skip this line.
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    20,971 Super User 2025 Season 2 on at
    Yes, ZHU is correct, to ensure that your Business Central process continues even if a validation fails, wrap your validation and insertion logic in a try method. This way, if an error occurs during validation (e.g., invalid currency code), it will be caught, logged to a custom error table, and the process will proceed to the next payment line without stopping. This approach allows you to handle errors gracefully and maintain processing continuity.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,116

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 764 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 635 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans