Skip to content

Commit 2ac1ba8

Browse files
Fix Sustainability preview posting subscriber (#27775)
<!-- 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]>
1 parent cb4a2a0 commit 2ac1ba8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Apps/W1/Sustainability/app/src/Purchase/SustPurchaseSubscriber.Codeunit.al

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ codeunit 6225 "Sust. Purchase Subscriber"
6161
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Preview", 'OnAfterBindSubscription', '', false, false)]
6262
local procedure OnAfterBindSubscription()
6363
begin
64-
SustPreviewPostInstance.Initialize();
65-
BindSubscription(SustPreviewPostingHandler);
64+
TryBindPostingPreviewHandler();
6665
end;
6766

6867
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Preview", 'OnAfterUnbindSubscription', '', false, false)]
6968
local procedure OnAfterUnbindSubscription()
7069
begin
71-
UnbindSubscription(SustPreviewPostingHandler);
70+
TryUnbindPostingPreviewHandler();
7271
end;
7372

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

286+
local procedure TryBindPostingPreviewHandler(): Boolean
287287
var
288288
SustPreviewPostingHandler: Codeunit "Sust. Preview Posting Handler";
289289
SustPreviewPostInstance: Codeunit "Sust. Preview Post Instance";
290+
begin
291+
SustPreviewPostInstance.Initialize();
292+
exit(BindSubscription(SustPreviewPostingHandler));
293+
end;
294+
295+
local procedure TryUnbindPostingPreviewHandler(): Boolean
296+
var
297+
SustPreviewPostingHandler: Codeunit "Sust. Preview Posting Handler";
298+
begin
299+
exit(UnbindSubscription(SustPreviewPostingHandler));
300+
end;
301+
302+
var
290303
EmissionMustNotBeZeroErr: Label 'The Emission fields must have a value that is not 0.';
291304
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.';
292305
}

0 commit comments

Comments
 (0)