Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Check if a decimal field is blank

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

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    You are absolutely right....I needed to set range, and I also included one for item as well. Thank you Mohana, always appreciated!!

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: Check if a decimal field is blank

    You have to apply filter on purchase line before repeat other wise it will check all the lines and if last line in that table has qty and direct unit cost then it wont show error.

    purchLine.SetRange("Document Type", PurchaseHeader."Document Type");

               purchLine.SetRange("Document No.", PurchaseHeader."No.");

               if purchLine.FindSet() then

                   repeat

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    Even though qty and direct unit cost are blank, it does not append to the error message....so i am assuming that the if condition doesn't work for those fields.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: Check if a decimal field is blank

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

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    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;
    }

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    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.

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: Check if a decimal field is blank

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

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    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
    Mohana Yadav 59,127 Super User 2024 Season 2 on at
    RE: Check if a decimal field is blank

    if purchLine."Direct Unit Cost" = 0 then

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

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Check if a decimal field is blank

    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 := '';

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans