Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Unanswered

Field Validation: Skip errors

Posted on by 289
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! 
 
 
Categories:
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    Khushbu Rajvi. 1,519 on at
    Field Validation: Skip errors
    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.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,842 Super User 2024 Season 2 on at
    Field Validation: Skip errors
    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

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,251 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans