Table 5065 "Interaction Log Entry" - Increment Entry No. proposals
Hello,
In our project we encountered many locking errors on the Interaction Log Entry table because the function that retrieves the next Entry No. does a LockTable and a FindLast:
codeunit 5051 SegManagement
local procedure GetNextInteractionLogEntryNo(): Integer
var
[SecurityFiltering(SecurityFilter::Ignored)]
InteractionLogEntry: Record "Interaction Log Entry";
begin
with InteractionLogEntry do begin
LockTable();
if FindLast then;
exit("Entry No." + 1);
end;
end;
Before Business Central we changed the AutoIncrement property of the field Entry No to true and did some related changes to let the Entry No to be autoincremented and not retrieved with LockTable and FindLast.
Hereby 2 alternative solutions for Business Central:
Solution 1
- Add IsHandled pattern in the procedure GetNextInteractionLogEntryNo
local procedure GetNextInteractionLogEntryNo(): Integer
var
[SecurityFiltering(SecurityFilter::Ignored)]
InteractionLogEntry: Record "Interaction Log Entry";
Result: Integer;
IsHandled: Boolean;
begin
// << add
IsHandled := false;
OnBeforeGetNextInteractionLogEntryNo(InteractionLogEntry, Result, IsHandled);
if IsHandled then
exit(Result);
// >> stop add
with InteractionLogEntry do begin
LockTable();
if FindLast then;
exit("Entry No." + 1);
end;
end;
[IntegrationEvent(false, false)]
local procedure OnBeforeGetNextInteractionLogEntryNo(InteractionLogEntry: Record "Interaction Log Entry"; var Result: Integer; var IsHandled: Boolean)
begin
end;
- Related changes are necessary: -> codeunit 5064 "Email Logging Dispatcher": replace
InteractLogEntry.Locktable();
IF InteractLogEntry.FindLast THEN
NextInteractLogEntryNo := InteractLogEntry."Entry No.";
with
NextInteractLogEntryNo := GetNextInteractionLogEntryNo();
-> Add upgrade codeunit in the BaseApp to set the NumberSequence that could be used to increment the EntryNo and the last Entry No used.
procedure UpgradePerCompany(var ProcessLogger: TextBuilder)
begin
CreateNewSequence();
end;
local procedure CreateNewSequence()
var
InteractionLogEntry: Record "Interaction Log Entry";
begin
if not NumberSequence.Exists(InteractionLogEntry.TableName) then
NumberSequence.Insert(InteractionLogEntry.TableName, UpdateStartingSequenceNo(), 1);
end;
local procedure UpdateStartingSequenceNo(): Integer
var
InteractionLogEntry: Record "Interaction Log Entry";
begin
InteractionLogEntry.LockTable();
if InteractionLogEntry.FindLast() then;
exit(InteractionLogEntry."Entry No." + 1);
end;
With these in place the Entry No. can be retrieved using NumberSequence:
[EventSubscriber(ObjectType::Codeunit, Codeunit::SegManagement, 'OnBeforeGetNextInteractionLogEntryNo', '', false, false)]
local procedure OnBeforeGetNextInteractionLogEntryNo(InteractionLogEntry: Record "Interaction Log Entry"; var Result: Integer; var IsHandled: Boolean)
begin
IsHandled := true;
Result := NumberSequence.Next(InteractionLogEntry.TableName);
end;
Solution 2
- Change the procedure GetNextInteractionLogEntryNo to retrieve the Entry No. using NumberSequence
local procedure GetNextInteractionLogEntryNo(): Integer
var
[SecurityFiltering(SecurityFilter::Ignored)]
InteractionLogEntry: Record "Interaction Log Entry";
begin
exit(NumberSequence.Next(InteractionLogEntry.TableName));
end;
end;
This change has to be done in the codeunits SegmentManagement and Email Logging Dispatcher. 2. Add upgrade codeunit in the BaseApp to set the NumberSequence that could be used to increment the EntryNo and the last Entry No used
procedure UpgradePerCompany(var ProcessLogger: TextBuilder)
begin
CreateNewSequence();
end;
local procedure CreateNewSequence()
var
InteractionLogEntry: Record "Interaction Log Entry";
begin
if not NumberSequence.Exists(InteractionLogEntry.TableName) then
NumberSequence.Insert(InteractionLogEntry.TableName, UpdateStartingSequenceNo(), 1);
end;
local procedure UpdateStartingSequenceNo(): Integer
var
InteractionLogEntry: Record "Interaction Log Entry";
begin
InteractionLogEntry.LockTable();
if InteractionLogEntry.FindLast() then;
exit(InteractionLogEntry."Entry No." + 1);
end;
Please consider these proposals and let us know your opinion. Of course any other idea that could be used to avoid locking errors will be highly appreciated.
Thank you in advance!
+1 ! Same for us !
Hi, can you please provide an update for this request? Thanks a lot!
@monicasuica, can you please revisit this request and check if it is still valid? SegManagement codeunit has gone through few changes in the recent past including the introduction of sequencing for interaction log entry number. Based on that let us know if this request still makes sense or should the request be changed.
Hi @ChethanT , the changes you provided are good enough for our solution and it was adjusted accordingly. The ticket can be closed.
Thank you!