Skip to content

Commit

Permalink
First steps to get background sending on the way
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Jan 10, 2024
1 parent e31e06e commit e526f85
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
10 changes: 6 additions & 4 deletions MSDyn365BC.Ntfy/src/EventTypes/SalesDocumentReleased.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
Body: Codeunit "Http Content";
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 @@ -46,12 +48,12 @@ codeunit 71179877 SalesDocumentReleasedNTSTM implements INtfyEventNTSTM
DoCall := not FilterSalesHeader.IsEmpty();
end;

if DoCall then begin
Body.Create(StrSubstNo('Sales %1 - %2 - has been released', SalesHeader."Document Type", SalesHeader."No."));
RestClient.Post(StrSubstNo('https://ntfy.sh/%1', NtfyEntry.NtfyTopic), Body).GetContent().AsText();
end;
if DoCall then
NtfyEntry.Mark(true);
until NtfyEntry.Next() = 0;

NtfyEntry.MarkedOnly(true);
NtfyEntry.RunBatch();
end;

}
28 changes: 28 additions & 0 deletions MSDyn365BC.Ntfy/src/foundation/BatchSendNtfys.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace StefanMaron.Ntfy;

using System.RestClient;

codeunit 71179879 BatchSendNtfysNTSTM
{
TableNo = NtfyEntryNTSTM;

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);

NtfyEntry.SetRange(EventType, NtfyEntry.EventType::SalesDocumentReopened);
NtfyEntry.SetFilter(NtfyTopic, '<>%1', '');
if NtfyEntry.FindSet() then
repeat
Clear(RestClient);
RestClient.Post(StrSubstNo('https://ntfy.sh/%1', NtfyEntry.NtfyTopic), Body);
until NtfyEntry.Next() = 0;
end;
}
10 changes: 10 additions & 0 deletions MSDyn365BC.Ntfy/src/foundation/NtfyEntry.Table.al
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ table 71179875 NtfyEntryNTSTM
INtfyEvent := Rec.EventType;
INtfyEvent.SetFilters(Rec);
end;

procedure RunBatch()
var
TempSessionId: Integer;
begin
Commit();
StartSession(TempSessionId, Codeunit::BatchSendNtfysNTSTM, CompanyName, Rec);
// if not TaskScheduler.CreateTask() then
// Codeunit.Run(Codeunit::BatchSendNtfysNTSTM, Rec);
end;
}

0 comments on commit e526f85

Please sign in to comment.