Skip to content

Commit

Permalink
Fix Sustainability preview posting subscriber (#27775)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request. If you're new to
contributing to AlAppExtensions please read our pull request guideline
below
* https://github.com/microsoft/ALAppExtensions/blob/main/CONTRIBUTING.md
-->
#### Summary <!-- Provide a general summary of your changes -->
Change the binding preview posting codeunits using try method like in
service posting
#### Work Item(s) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes #27706


Fixes
[AB#559882](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/559882)

Co-authored-by: Vladyslav Kovalchuk <[email protected]>
  • Loading branch information
vlkov and VladyslavxKovalchuk authored Dec 13, 2024
1 parent cb4a2a0 commit 2ac1ba8
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ codeunit 6225 "Sust. Purchase Subscriber"
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Preview", 'OnAfterBindSubscription', '', false, false)]
local procedure OnAfterBindSubscription()
begin
SustPreviewPostInstance.Initialize();
BindSubscription(SustPreviewPostingHandler);
TryBindPostingPreviewHandler();
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Preview", 'OnAfterUnbindSubscription', '', false, false)]
local procedure OnAfterUnbindSubscription()
begin
UnbindSubscription(SustPreviewPostingHandler);
TryUnbindPostingPreviewHandler();
end;

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", 'OnPostItemJnlLineOnAfterPrepareItemJnlLine', '', false, false)]
Expand Down Expand Up @@ -284,9 +283,23 @@ codeunit 6225 "Sust. Purchase Subscriber"
exit(true);
end;

local procedure TryBindPostingPreviewHandler(): Boolean
var
SustPreviewPostingHandler: Codeunit "Sust. Preview Posting Handler";
SustPreviewPostInstance: Codeunit "Sust. Preview Post Instance";
begin
SustPreviewPostInstance.Initialize();
exit(BindSubscription(SustPreviewPostingHandler));
end;

local procedure TryUnbindPostingPreviewHandler(): Boolean
var
SustPreviewPostingHandler: Codeunit "Sust. Preview Posting Handler";
begin
exit(UnbindSubscription(SustPreviewPostingHandler));
end;

var
EmissionMustNotBeZeroErr: Label 'The Emission fields must have a value that is not 0.';
NotAllowedToPostSustLedEntryForWaterOrWasteErr: Label 'It is not allowed to post Sustainability Ledger Entry for water or waste in purchase document for Account No. %1', Comment = '%1 = Sustainability Account No.';
}

0 comments on commit 2ac1ba8

Please sign in to comment.