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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Check if a decimal field is blank

(0) ShareShare
ReportReport
Posted on by 130

Hi all,

I can't find a satisfactory answer to this question.

I want to evaluate a decimal field - if it is blank (no value inputted) then I would like to raise an error.

Thank you

I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 on at

    You can check

    If Decimalfield = 0 then

     error('Field is blank');

  • SammySevens Profile Picture
    130 on at

    Unless I am doing something wrong, that does not work :S 

  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 on at

    can you share your code?

  • SammySevens Profile Picture
    130 on at

    Yes for sure

    if purchLine."Direct Unit Cost" = 0 then begin
                        purchLineCostErr := 'Please enter a direct unit cost for the item in the purchase line';
                        errorState := true;
                    end
                    else
                        purchLineCostErr := '';

  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 on at

    if purchLine."Direct Unit Cost" = 0 then

                       Error('Please enter a direct unit cost for the item in the purchase line');

  • SammySevens Profile Picture
    130 on at

    I am evaluating several fields in my code unit, so i call error at the end and append all missing fields into one error call.

    Can i leave "begin" someway?

  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 on at

    yes, what error are you getting with the above code?

  • SammySevens Profile Picture
    130 on at

    With above code it will create an error just for this condition....i would like 1 error at end of codeunit that aggregates 8 field evaluations.

  • SammySevens Profile Picture
    130 on at

    Here is full code for reference

    codeunit 60005 c60005CheckQuoteBeforeApproval
    {
        [EventSubscriber(ObjectType::Codeunit, Codeunit::"Approvals Mgmt.", 'OnBeforeCheckPurchaseApprovalPossible', '', false, false)]
        local procedure MyProcedure(var PurchaseHeader: Record "Purchase Header")
        var
            purchLine: Record "Purchase Line";
            origRequestorErr: Text[100];
            requestReceiptDateErr: Text[100];
            departmentCodeErr: Text[100];
            purchLineNoErr: Text[100];
            purchLineDescErr: Text[100];
            purchLineQtyErr: Text[100];
            purchLineCostErr: Text[100];
            purchLineReasonErr: Text[100];
            errorState: Boolean;
        begin
            if purchaseHeader."Document Type" = purchaseHeader."Document Type"::Quote then begin
                if purchaseHeader.origRequestor = '' then begin
                    origRequestorErr := 'Please enter an Original Requestor';
                    errorState := true;
                end
                else
                    origRequestorErr := '';
    
                if PurchaseHeader."Requested Receipt Date" = 0D then begin
                    requestReceiptDateErr := 'Please enter a Requested Receipt Date';
                    errorState := true;
                end
                else
                    requestReceiptDateErr := '';
    
                if PurchaseHeader.departmentName = '' then begin
                    departmentCodeErr := 'Please enter a Department Code';
                    errorState := true
                end
                else
                    departmentCodeErr := '';
    
                repeat
                    if purchLine."No." = '' then begin
                        purchLineNoErr := 'Please enter an Item No. in the Purchase Line';
                        errorState := true
                    end
                    else
                        purchLineNoErr := '';
    
                    if purchLine.multiLineDescription = '' then begin
                        purchLineDescErr := 'Please enter a Description for the Item in the Purchase Line';
                        errorState := true;
                    end
                    else
                        purchLineDescErr := '';
    
                    if purchLine.reasonForRequest = '' then begin
                        purchLineReasonErr := 'Please enter a Reason for the Item in the Purchase Line';
                        errorState := true;
                    end
                    else
                        purchLineReasonErr := '';
    
                    if purchLine.Quantity = 0 then begin
                        purchLineQtyErr := 'Please enter a quantity for the item in the purchase line';
                        errorState := true;
                    end
                    else
                        purchLineQtyErr := '';
    
                    if purchLine."Direct Unit Cost" = 0 then begin
                        purchLineCostErr := 'Please enter a direct unit cost for the item in the purchase line';
                        errorState := true;
                    end
                    else
                        purchLineCostErr := '';
    
                until purchLine.next = 0;
    
            end;
            if errorState = true then
                Error('%1 \ %2 \ %3 \ %4 \ %5 \ %6 \ %7 \ %8', origRequestorErr, requestReceiptDateErr, departmentCodeErr, purchLineNoErr, purchLineDescErr, purchLineReasonErr, purchLineQtyErr, purchLineCostErr) // include the variable placeholders '%1', Error('there are errors on this page %1 \ %2 \ %3', origRequestorErr, requestReceiptDate.....)
            else
                errorState := false;
    
        end;
    }

  • Suggested answer
    Mohana Yadav Profile Picture
    61,204 Super User 2026 Season 1 on at

    Can you explain what is the issue or what is not working?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,926 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,158 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 533 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans