Skip to content

Commit

Permalink
Get rid off commit and iso storage workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Jan 11, 2024
1 parent 6d6c71d commit 54dd037
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
NtfyEntry: Record NtfyEntryNTSTM;
DoCall: Boolean;
begin
IsolatedStorage.Set('NtfyDescription', StrSubstNo('Sales %1 - %2 - has been released', SalesHeader."Document Type", SalesHeader."No."), DataScope::User);

NtfyEntry.SetRange(EventType, NtfyEntry.EventType::SalesDocumentReleased);
NtfyEntry.SetFilter(NtfyTopic, '<>%1', '');
if NtfyEntry.FindSet() then
Expand All @@ -48,6 +46,8 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
NtfyEntry.Mark(true);
until NtfyEntry.Next() = 0;

NtfyEntry.NtfyMessage := StrSubstNo('Sales %1 - %2 - has been released', SalesHeader."Document Type", SalesHeader."No.");

NtfyEntry.MarkedOnly(true);
NtfyEntry.RunBatch();
end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ codeunit 71179878 SalesDocumentReopenedNTSTM implements INtfyEventNTSTM
NtfyEntry: Record NtfyEntryNTSTM;
DoCall: Boolean;
begin
IsolatedStorage.Set('NtfyDescription', StrSubstNo('Sales %1 - %2 - has been released', SalesHeader."Document Type", SalesHeader."No."), DataScope::User);

NtfyEntry.SetRange(EventType, NtfyEntry.EventType::SalesDocumentReopened);
NtfyEntry.SetFilter(NtfyTopic, '<>%1', '');
if NtfyEntry.FindSet() then
Expand All @@ -48,6 +46,8 @@ codeunit 71179878 SalesDocumentReopenedNTSTM implements INtfyEventNTSTM
NtfyEntry.Mark(true);
until NtfyEntry.Next() = 0;

NtfyEntry.NtfyMessage := StrSubstNo('Sales %1 - %2 - has been reopened', SalesHeader."Document Type", SalesHeader."No.");

NtfyEntry.MarkedOnly(true);
NtfyEntry.RunBatch();
end;
Expand Down
12 changes: 4 additions & 8 deletions MSDyn365BC.Ntfy/src/foundation/BatchSendNtfys.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ codeunit 71179879 BatchSendNtfysNTSTM

trigger OnRun()
var
NtfyEntry: Record NtfyEntryNTSTM;
RestClient: Codeunit "Rest Client";
Body: Codeunit "Http Content";
Description: Text;
begin
IsolatedStorage.Get('NtfyDescription', DataScope::User, Description);
Body.Create(Description);
IsolatedStorage.Delete('NtfyDescription', DataScope::User);
Body.Create(Rec.NtfyMessage);

if NtfyEntry.FindSet() then
if Rec.FindSet() then
repeat
Clear(RestClient);
RestClient.Post(StrSubstNo('https://ntfy.sh/%1', NtfyEntry.NtfyTopic), Body);
until NtfyEntry.Next() = 0;
RestClient.Post(StrSubstNo('https://ntfy.sh/%1', Rec.NtfyTopic), Body);
until Rec.Next() = 0;
end;
}
11 changes: 10 additions & 1 deletion MSDyn365BC.Ntfy/src/foundation/NtfyEntry.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ table 71179875 NtfyEntryNTSTM
AllowInCustomizations = Never;
Caption = 'Filter Text';
}
field(5; NtfyTitle; Text[150])
{
Caption = 'Title';
//Temporary user only
}
field(6; NtfyMessage; Text[2048])
{
Caption = 'Message';
//Temporary user only
}
}

keys
Expand All @@ -52,7 +62,6 @@ table 71179875 NtfyEntryNTSTM
var
TempSessionId: Integer;
begin
Commit(); //Need to commit the isolated storage so the background session can read the data
if not StartSession(TempSessionId, Codeunit::BatchSendNtfysNTSTM, CompanyName, Rec) then
Codeunit.Run(Codeunit::BatchSendNtfysNTSTM, Rec);

Expand Down

0 comments on commit 54dd037

Please sign in to comment.