Skip to content

Commit

Permalink
Add notifications for Approval Requests
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanMaron committed Apr 16, 2024
1 parent bf16574 commit 45f5910
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
57 changes: 57 additions & 0 deletions MSDyn365BC.Ntfy/src/EventTypes/ApprovalRequested.Codeunit.al
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace StefanMaron.Ntfy;
using Microsoft.Sales.Document;
using System.Automation;

codeunit 71179884 ApprovalRequestedNTSTM implements INtfyEventNTSTM
{

procedure SetSettings(NtfyEvent: Record NtfyEventNTSTM)
var
FilterPageBuilder: FilterPageBuilder;
begin
FilterPageBuilder.AddTable('Approval Entry', Database::"Approval Entry");
if NtfyEvent.FilterText <> '' then
FilterPageBuilder.SetView('Approval Entry', NtfyEvent.FilterText);
if FilterPageBuilder.RunModal() then begin
if not FilterPageBuilder.GetView('Approval Entry').Contains('WHERE') then
NtfyEvent.Validate(FilterText, '')
else
NtfyEvent.Validate(FilterText, FilterPageBuilder.GetView('Approval Entry'));
NtfyEvent.Modify(true);
end;
end;

procedure ResetSettings(NtfyEvent: Record NtfyEventNTSTM);
begin
NtfyEvent.Validate(FilterText, '');
NtfyEvent.Modify(true);
end;

procedure FilterNtfyEntriesBeforeBatchSend(var NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]);
begin
NtfyEvent.SetRange(UserName, Params.Get('ApproverID'));
end;

procedure DoCallNtfyEvent(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Boolean
begin
exit(true);
end;

procedure GetMessage(NtfyEvent: Record NtfyEventNTSTM; Params: Dictionary of [Text, Text]) ReturnValue: Text[2048]
begin
exit(StrSubstNo('%1 | Pending Approval [Go to Approval List](%2)', Params.Get('RecordID'), GetUrl(ClientType::Web, CompanyName, ObjectType::Page, Page::"Requests to Approve")));
end;

[EventSubscriber(ObjectType::Table, Database::"Approval Entry", OnAfterInsertEvent, '', false, false)]
local procedure SentNtfyOnAfterReopenSalesDoc(var Rec: Record "Approval Entry")
var
NtfyEvent: Record NtfyEventNTSTM;
Params: Dictionary of [Text, Text];
begin
if not (Rec.Status in [Rec.Status::Open, Rec.Status::Created]) then exit;

Params.Add('ApproverID', Rec."Approver ID");
Params.Add('RecordID', Format(Rec."Record ID to Approve"));
NtfyEvent.SendNotifications(NtfyEvent.EventType::ApprovalRequested, Params);
end;
}
5 changes: 5 additions & 0 deletions MSDyn365BC.Ntfy/src/EventTypes/EventType.Enum.al
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ enum 71179875 EventTypeNTSTM implements INtfyEventNTSTM
Caption = 'Report finished processing';
Implementation = INtfyEventNTSTM = ReportFinishedProcessingNTSTM;
}
value(4; ApprovalRequested)
{
Caption = 'Approval requested';
Implementation = INtfyEventNTSTM = ApprovalRequestedNTSTM;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ codeunit 71179880 RestWrapperNTSTM implements IRestWrapperNTSTM
var
RestClient: Codeunit "Rest Client";
begin
RestClient.SetDefaultRequestHeader('Markdown', 'yes');
exit(RestClient.Post(RequestUri, Content));
end;
}
5 changes: 3 additions & 2 deletions al.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"Ntfy",
"Ntfys",
"NTSTM"
]
],
"al.rootNamespace": "StefanMaron.Ntfy",
}
}
}

0 comments on commit 45f5910

Please sign in to comment.