Add condition to CheckBalance function in Gen Journal Post Batch

Hi,

we are trying to add an addtional check to the postbatch function.

Essentially we want to check a custom enum value of every Line (Record) and then make an operation.

So far we tried:

local procedure CheckBalance(var GenJnlLine: Record "Gen. Journal Line edelb")

var
    myenum2: enum myEnum;
    myValue: Integer; 
    Edel_Text: Text[20]

foreach Value in enum::myEnum.Ordinals() do begin
if (myenum2 = myenum2::Ag) then

                  ..................
                break;
        end;

However iteration does not break, eventhough the variables are ok.

Anybody know how to iterate the enum value of every record in this codeunit?

Thanks,

DeFi

It seems like you are trying to iterate over the ordinal values of your custom enum, but you are not actually setting the value of myenum2 in the loop. Therefore, the if condition will never evaluate to true, and the loop will not break.

To iterate over the enum value of every record in the codeunit, you can use a RecordRef variable and the SETRANGE function to filter the records based on your custom enum value. Here’s an example of how you could modify your code:

local procedure CheckBalance(var GenJnlLine: Record “Gen. Journal Line edelb”) var GenJnlLineRef: RecordRef; myenum2: enum myEnum; begin GenJnlLineRef.OPEN(GenJnlLine); GenJnlLineRef.SETRANGE(“Custom Enum Field”, myenum2);

if GenJnlLineRef.ISEMPTY then // no records match the filter condition else begin repeat // do something with the filtered records here until GenJnlLineRef.NEXT = 0; end; end;

In this example, replace "Custom Enum Field" with the actual field name of your custom enum field.

By using a RecordRef and the SETRANGE function, you can filter the records based on your custom enum value and then loop through them to perform your custom operation.