Skip to content

Commit

Permalink
No. Series: Add telemetry (#607)
Browse files Browse the repository at this point in the history
Adding telemetry to No. Series to determine if something fails and why.

Fixes
[AB#496416](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/496416)
  • Loading branch information
AndreasMoth authored Feb 21, 2024
1 parent 91c0d2c commit 78495ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ codeunit 309 "No. Series - Batch Impl."
SimulationMode: Boolean;
CannotSaveNonExistingNoSeriesErr: Label 'Cannot save No. Series Line that does not exist: %1, %2', Comment = '%1 = No. Series Code, %2 = Line No.';
CannotSaveWhileSimulatingNumbersErr: Label 'No. Series state cannot be saved while simulating numbers.';
NoSeriesBatchTxt: Label 'No. Series - Batch', Locked = true;
SimulationModeStartedTxt: Label 'No. Series simulation mode started.', Locked = true;
SavingSingleNoSeriesStateTxt: Label 'Saving single No. Series state.', Locked = true;
SavingAllNoSeriesStatesTxt: Label 'Saving all No. Series states.', Locked = true;
UpdatingNoSeriesLinesFromDbTxt: Label 'Updating No. Series lines from database.', Locked = true;

procedure SetInitialState(TempNoSeriesLine: Record "No. Series Line" temporary)
begin
Expand Down Expand Up @@ -124,6 +129,10 @@ codeunit 309 "No. Series - Batch Impl."

procedure SetSimulationMode()
begin
if SimulationMode then
exit;

Session.LogMessage('0000MI2', SimulationModeStartedTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesBatchTxt);
SimulationMode := true;
end;

Expand All @@ -133,13 +142,15 @@ codeunit 309 "No. Series - Batch Impl."
Error(CannotSaveWhileSimulatingNumbersErr);
if not TempGlobalNoSeriesLine.Get(TempNoSeriesLine."Series Code", TempNoSeriesLine."Line No.") then
Error(CannotSaveNonExistingNoSeriesErr, TempNoSeriesLine."Series Code", TempNoSeriesLine."Line No.");
Session.LogMessage('0000MI3', SavingSingleNoSeriesStateTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesBatchTxt);
UpdateNoSeriesLine(TempGlobalNoSeriesLine);
end;

procedure SaveState();
begin
if SimulationMode then
Error(CannotSaveWhileSimulatingNumbersErr);
Session.LogMessage('0000MI4', SavingAllNoSeriesStatesTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesBatchTxt);
TempGlobalNoSeriesLine.Reset();
if TempGlobalNoSeriesLine.FindSet() then
repeat
Expand All @@ -152,6 +163,7 @@ codeunit 309 "No. Series - Batch Impl."
var
NoSeriesLine: Record "No. Series Line";
begin
Session.LogMessage('0000MI5', UpdatingNoSeriesLinesFromDbTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesBatchTxt);
NoSeriesLine.Get(TempNoSeriesLine."Series Code", TempNoSeriesLine."Line No.");
NoSeriesLine.TransferFields(TempNoSeriesLine);
NoSeriesLine.Modify(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ codeunit 307 "No. Series - Sequence Impl." implements "No. Series - Single"

var
NoOverFlowErr: Label 'Number series can only use up to 18 digit numbers. %1 has %2 digits.', Comment = '%1 is a string that also contains digits. %2 is a number.';
NoSeriesSequenceTxt: Label 'No. Series - Sequence', Locked = true;
UpdatingSequenceBasedOnTempValueTxt: Label 'Updating sequence based on temporary value.', Locked = true;

procedure PeekNextNo(NoSeriesLine: Record "No. Series Line"; UsageDate: Date): Code[20]
begin
Expand Down Expand Up @@ -325,8 +327,11 @@ codeunit 307 "No. Series - Sequence Impl." implements "No. Series - Single"
if NoSeriesLine."Temp Current Sequence No." = 0 then
exit;

if NoSeriesLine.Implementation = "No. Series Implementation"::Sequence then
if NoSeriesLine.Implementation = "No. Series Implementation"::Sequence then begin
Session.LogMessage('0000MI6', UpdatingSequenceBasedOnTempValueTxt, Verbosity::Normal, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesSequenceTxt);
RecreateNoSeriesWithLastUsedNo(NoSeriesLine, NoSeriesLine."Temp Current Sequence No.");
end;


NoSeriesLine."Temp Current Sequence No." := 0; // Always reset the temporary sequence number!
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ codeunit 306 "No. Series - Stateless Impl." implements "No. Series - Single"
var
CannotAssignNumbersGreaterThanErr: Label 'You cannot assign numbers greater than %1 from the number series %2. No. assigned: %3', Comment = '%1=Last No.,%2=No. Series Code, %3=the new no.';
WarnNoSeriesRunningOutMsg: Label 'The No. Series %1 is soon running out. The current number is %2 and the last allowed number of the sequence is %3.', Comment = '%1=No. Series code,%2=Current No.,%3=Last No. of the sequence';
NoSeriesTxt: Label 'No. Series', Locked = true;
NoSeriesOutOfRangeTxt: Label 'The last number used is outside range.', Locked = true;
NoSeriesWarningTxt: Label 'The No. Series is running out of numbers.', Locked = true;

procedure PeekNextNo(NoSeriesLine: Record "No. Series Line"; UsageDate: Date): Code[20]
begin
Expand Down Expand Up @@ -85,12 +88,14 @@ codeunit 306 "No. Series - Stateless Impl." implements "No. Series - Single"
NoSeriesErrorsImpl: Codeunit "No. Series - Errors Impl.";
begin
if not NoIsWithinValidRange(NoSeriesLine."Last No. Used", NoSeriesLine."Starting No.", NoSeriesLine."Ending No.") then begin
Session.LogMessage('0000MI7', NoSeriesOutOfRangeTxt, Verbosity::Error, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesTxt);
if NoErrorsOrWarnings then
exit(false);
NoSeriesErrorsImpl.Throw(StrSubstNo(CannotAssignNumbersGreaterThanErr, NoSeriesLine."Ending No.", NoSeriesLine."Series Code", NoSeriesLine."Last No. Used"), NoSeriesLine, NoSeriesErrorsImpl.OpenNoSeriesLinesAction());
end;

if (NoSeriesLine."Ending No." <> '') and (NoSeriesLine."Warning No." <> '') and (NoSeriesLine."Last No. Used" >= NoSeriesLine."Warning No.") then begin
Session.LogMessage('0000MI8', NoSeriesWarningTxt, Verbosity::Warning, DataClassification::SystemMetadata, TelemetryScope::ExtensionPublisher, 'Category', NoSeriesTxt);
if NoErrorsOrWarnings then
exit(false);
if GuiAllowed() then
Expand Down

0 comments on commit 78495ed

Please sign in to comment.