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
You are absolutely right....I needed to set range, and I also included one for item as well. Thank you Mohana, always appreciated!!
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
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.
Can you explain what is the issue or what is not working?
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; }
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.
yes, what error are you getting with the above code?
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?
if purchLine."Direct Unit Cost" = 0 then
Error('Please enter a direct unit cost for the item in the purchase line');
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 := '';
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156