Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No. Series: Ability to extend filters on finding No. Series Lines when getting new numbers #2361

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

PeterDurrer
Copy link

@PeterDurrer PeterDurrer commented Nov 14, 2024

Summary

Add Event for No. Series

Work Item(s)

Fixes #1362

@PeterDurrer PeterDurrer requested a review from a team as a code owner November 14, 2024 08:07
@github-actions github-actions bot added AL: Business Foundation From Fork Pull request is coming from a fork labels Nov 14, 2024
@PeterDurrer PeterDurrer changed the title https://github.com/microsoft/BCApps/issues/1362#issue-2360774022 No. Series: Ability to extend filters on finding No. Series Lines when getting new numbers Nov 14, 2024
@PeterDurrer PeterDurrer reopened this Nov 14, 2024
@PeterDurrer
Copy link
Author

PeterDurrer commented Nov 14, 2024

@PeterDurrer please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Logico Solutions AG"

@@ -189,6 +190,7 @@ codeunit 304 "No. Series - Impl."
if (NoSeriesLine."Line No." <> 0) and (NoSeriesLine."Series Code" = NoSeriesCode) and (NoSeriesLine."Starting Date" = NoSeriesLine2."Starting Date") then begin
NoSeriesLine.CopyFilters(NoSeriesLine2);
NoSeriesLine.SetRange("Line No.", NoSeriesLine."Line No.");
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed as we copy all filters from NoSeriesLine2, including the filters you would have set in the previous call.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, only the first one is needed, I had included it because the RaiseObsoleteOnNoSeriesLineFilterOnBeforeFindLast was present there.

NoSeriesManagement.RaiseObsoleteOnNoSeriesLineFilterOnBeforeFindLast(NoSeriesLine);
LineFound := NoSeriesLine.FindLast();
end;
#pragma warning restore AL0432
#else
if not LineFound then
if not LineFound then begin
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NoSeriesLine has copied filters from NoSeriesLine2 above so this should not be needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, only the first one is needed, I had included it because the RaiseObsoleteOnNoSeriesLineFilterOnBeforeFindLast was present there.

@@ -101,6 +101,7 @@ codeunit 305 "No. Series - Setup Impl."
NoSeriesLine.SetCurrentKey("Series Code", "Starting Date");
NoSeriesLine.SetRange("Series Code", NoSeriesRec.Code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract these three lines into a function in the setup impl. codeunit like below. This allows anyone to set filters without potentially messing up with the record. Pure setting of filters which is what we need and they have access to what code and date we are trying to filter to.
GetNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line", code, date)
var
var NoSeriesLine2: Record "No. Series Line"
begin
NoSeriesLine2.SetRange("Starting Date", 0D, date);
NoSeriesLine2.SetRange("Series Code", code)
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2)
If NoSeriesLine2. <> code then
Error(CodeFieldChangedErr); // Extensions should never change the code field range, this is a bug that developers should know immediately.
NoSeriesLine.CopyFilters(NoSeriesLine2);
end;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After extracting this, I think it looks pretty good :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope I understood you correctly about outsourcing the code, otherwise just let me know what the function should look like.

@@ -177,6 +177,7 @@ codeunit 304 "No. Series - Impl."
NoSeriesLine2.SetCurrentKey("Series Code", "Starting Date");
NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
NoSeriesLine2.SetRange("Starting Date", 0D, UsageDate);
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also call into GetNoSeriesLineFilters

Copy link
Contributor

@AndreasMoth AndreasMoth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need the other event to call the new GetNoSeriesLineFilters procedure as well.

NoSeriesLine2.SetRange("Starting Date", 0D, StartingDate);
NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
If NoSeriesLine2."Series Code" <> NoSeriesCode then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if NoSeriesLine2.GetFilter("Series Code") <> NoSeriesCode then" - that's what I meant. Do verify this is what GetFilter actually returns, I didn't test this completely :)

@@ -88,7 +88,7 @@ codeunit 305 "No. Series - Setup Impl."
NoSeries.MarkedOnly(true);
end;

local procedure SetNoSeriesCurrentLineFilters(var NoSeriesRec: Record "No. Series"; var NoSeriesLine: Record "No. Series Line"; ResetForDrillDown: Boolean)
procedure SetNoSeriesCurrentLineFilters(var NoSeriesRec: Record "No. Series"; var NoSeriesLine: Record "No. Series Line"; ResetForDrillDown: Boolean)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer needs to be public

@@ -137,6 +135,23 @@ codeunit 305 "No. Series - Setup Impl."
exit(NoSeriesSingle.MayProduceGaps());
end;

local procedure GetNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line"; NoSeriesCode: Code[20]; StartingDate: Date)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local procedure GetNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line"; NoSeriesCode: Code[20]; StartingDate: Date)
procedure SetNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line"; NoSeriesCode: Code[20]; StartingDate: Date)

var
NoSeries: Codeunit "No. Series";
NoSeriesLine2: Record "No. Series Line";
CodeFieldChangedErr: Label 'Change of Series Code Field is on this Record not allowed.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We add labels as global variables.

Suggested change
CodeFieldChangedErr: Label 'Change of Series Code Field is on this Record not allowed.';
CodeFieldChangedErr: Label 'The filter on Series Code was altered by an event subscriber. This is a programming error. Please contact your partner to resolve the issue.\Original Series Code: %1\Modified Filter: %2';

NoSeriesLine2.SetCurrentKey("Series Code", "Starting Date");
NoSeriesLine2.SetRange("Starting Date", 0D, StartingDate);
NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
OnSetNoSeriesLineFilters(NoSeriesLine2);

NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
If NoSeriesLine2."Series Code" <> NoSeriesCode then
Error(CodeFieldChangedErr); // Extensions should never change the code field range, this is a bug that developers should know immediately.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error(CodeFieldChangedErr); // Extensions should never change the code field range, this is a bug that developers should know immediately.
Error(CodeFieldChangedErr, NoSeriesCode, NoSeriesLine2.GetFilter("Series Code"); // Extensions should never change the code field range, this is a bug that developers should know immediately.

@@ -389,4 +404,9 @@ codeunit 305 "No. Series - Setup Impl."
if NumberSequence.Exists(Rec."Sequence Name") then
NumberSequence.Delete(Rec."Sequence Name");
end;

[IntegrationEvent(false, false)]
internal procedure RaiseSetAdditionalNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The event publisher should be added in NoSeries.Codeunit.al, not here

NoSeriesLine2.SetCurrentKey("Series Code", "Starting Date");
NoSeriesLine2.SetRange("Starting Date", 0D, StartingDate);
NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RaiseSetAdditionalNoSeriesLineFilters(NoSeriesLine2);
NoSeries.OnSetNoSeriesLineFilters(NoSeriesLine2);

/// </summary>
/// <param name="NoSeriesLine">The No. Series Line to set filters on.</param>
[IntegrationEvent(false, false)]
internal procedure OnGetNoSeriesLineOnBeforeFindLast(var NoSeriesLine: Record "No. Series Line");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal procedure OnGetNoSeriesLineOnBeforeFindLast(var NoSeriesLine: Record "No. Series Line");
internal procedure OnSetNoSeriesLineFilters(var NoSeriesLine: Record "No. Series Line");

/// <summary>
/// Use this event to change the filters set on the No. Series Line record. These filters are used when searching the No. Series.
/// </summary>
/// <param name="NoSeriesLine">The No. Series Line to set filters on.</param>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <param name="NoSeriesLine">The No. Series Line to set filters on.</param>
/// <remarks>Changing the filter on the "Series Code" field is not allowed and will result in an error.</remarks>
/// <param name="NoSeriesLine">The No. Series Line to set filters on.</param>

@@ -362,4 +362,13 @@ codeunit 310 "No. Series"
internal procedure OnAfterSetNoSeriesCurrentLineFilters(NoSeries: Record "No. Series"; var NoSeriesLine: Record "No. Series Line"; IsDrillDown: Boolean);
begin
end;

/// <summary>
/// Use this event to change the filters set on the No. Series Line record. These filters are used when searching the No. Series.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Use this event to change the filters set on the No. Series Line record. These filters are used when searching the No. Series.
/// Use this event to set additional filters on the No. Series Line record. These filters are used when searching the No. Series.

@@ -177,6 +177,7 @@ codeunit 304 "No. Series - Impl."
NoSeriesLine2.SetCurrentKey("Series Code", "Starting Date");
NoSeriesLine2.SetRange("Series Code", NoSeriesCode);
NoSeriesLine2.SetRange("Starting Date", 0D, UsageDate);
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine2);
NoSeriesSetupImpl.SetNoSeriesLineFilters(NoSeriesLine2, NoSeriesCode, UsageDate);

@JesperSchulz JesperSchulz added the Integration GitHub request for Integration area label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AL: Business Foundation From Fork Pull request is coming from a fork Integration GitHub request for Integration area
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No. Series: Ability to extend filters on finding No. Series Lines when getting new numbers
4 participants