Hi all,
I have created a codeunit based on an event subscriber to update Gen G/L line dimension codes, but receive this error
The transaction cannot be completed because it will cause inconsistencies in the G/L Entry table. Check where and how the CONSISTENT function is used in the transaction to find the reason for the error.
This is the code unit and idea is automatically fill in the dimensions before posting manual journal
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", 'OnBeforePostGenJnlLine', '', true, true)]
procedure UpdateDim(var GenJournalLine: Record "Gen. Journal Line");//; Balancing: Boolean
var
begin
if GenJournalLine."Journal Batch Name" = 'DEFAULT' then
GenJournalLine.SetRange("Journal Template Name", GenJournalLine."Journal Template Name");
GenJournalLine.SetRange("Line No.", GenJournalLine."Line No.");
if GenJournalLine.FindFirst() then begin
if GenJournalLine.get(GenJournalLine."Journal Template Name", GenJournalLine."Line No.") then
GenJournalLine.Validate("Shortcut Dimension 1 Code", 'A');
GenJournalLine.Validate("Shortcut Dimension 2 Code", 'B');
GenJournalLine.Modify(true);
end;
end;