-
Notifications
You must be signed in to change notification settings - Fork 169
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
base: main
Are you sure you want to change the base?
Conversation
…eplaces the backwards compatible Event
…eplaces the backwards compatible Event
@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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…eplaces the backwards compatible Event
@@ -101,6 +101,7 @@ codeunit 305 "No. Series - Setup Impl." | |||
NoSeriesLine.SetCurrentKey("Series Code", "Starting Date"); | |||
NoSeriesLine.SetRange("Series Code", NoSeriesRec.Code); |
There was a problem hiding this comment.
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;
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.'; |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NoSeries.OnGetNoSeriesLineOnBeforeFindLast(NoSeriesLine2); | |
NoSeriesSetupImpl.SetNoSeriesLineFilters(NoSeriesLine2, NoSeriesCode, UsageDate); |
Summary
Add Event for No. Series
Work Item(s)
Fixes #1362