Update Purchase Price record in a CodeUnit

Hello all,

First of all, thank you for this great forum. This is my first post here, but I’ve already found a lot of useful information!

I added a boolean field in the “Purchase Price” table (7012). I want this field to be checked only once for an item.
For this, I created a CodeUnit but it does not work as expected… Here is the code:

local procedure AfValPurchasePriceUsualSupply(CurrFieldNo: Integer; var Rec: Record "Purchase Price"; var xRec: Record "Purchase Price")
var
    lItemPurchasePrices: Record "Purchase Price";
begin
    if Rec.UsualSupply then begin
        lItemPurchasePrices.SetRange("Item No.", Rec."Item No.");
        if lItemPurchasePrices.FindSet() then
            repeat
                // Message('User input: ' + Rec."Vendor No." + ' - System verification: ' + lItemPurchasePrices."Vendor No.");
                if lItemPurchasePrices."Vendor No." <> Rec."Vendor No." then begin
                    // Message('Bingo!');
                    lItemPurchasePrices.UsualSupply := false;
                end;
            until (lItemPurchasePrices.Next = 0);
    end;
end;

This code loops well on all the “Purchase Price” lines of the item, but the update of the “UsualSupply” field is not done and I end up with two checked boxes instead of one.

UsualSupply|572x122

Do you know why?

Thank you!!

1 Like

Okay, my bad :grinning:

I just forgot the Modify method…

if lItemPurchasePrices."Vendor No." <> Rec."Vendor No." then begin
    lItemPurchasePrices.UsualSupply := false;
    lItemPurchasePrices.Modify();
end;

It works great.
Thanks