Individueller Objekt-Aufruf (Lohnabrechnung etc.)

Task #6937 und #10748 | 5058.000 

 

1.)How do Events work?
The rationale is that Publisher events are programmed in the application and then perform custom actions when they take place.

1.)Starting from which version are Events available?
Events are supported starting from version NAV 2016 and up to and including the latest BC version.

2.)Use cases published by SwissSalary
SwissSalary has published two use cases.
Partners can take advantage of the released Publisher events in their solutions.

For this purpose, partners can program a subscriber event that waits for a released Publisher event and then deals with it. A subscriber enables partners to hook into the core functionality of the application without having to make traditional code changes.

-Adjusted payslip use case

Save the adjusted payslip as a PDF

Send the adjusted to Direct

-Adjusted wage statement use case

Save the adjusted wage statement as a PDF

Send the adjusted wage statement to Direct

3.)Sample codes for Subscriber events

[EventSubscriber(ObjectType::Codeunit, Codeunit::"SwS Bulk Report Management", 'OnBeforeSavePaycheckAsPdf', '', false, false)]

local procedure HandleOnBeforeSavePaycheckAsPdf(pPayrollHead: Record "SwS Payroll Head"; pReportID: Integer; pReportParams: Record "SwS Working Table"; var pDescription: Text[1024]; var pHandled: Boolean; var pPaycheckTempBlob: Record "SwS TempBlob")

begin

   SaveCustomPaycheckAsPdf(pPayrollHead, pReportParams, pPaycheckTempBlob, pDescription);

   pHandled := true;

end;

local procedure SaveCustomPaycheckAsPdf(pPayrollHead: Record "SwS Payroll Head"; pReportParams: Record "SwS Working Table" temporary; var pPaycheckTempBlob: Record "SwS TempBlob"; var pDescription: Text[1024])

var

   CustomReport: Report "SwS Custom Paycheck";

   Employee: Record "SwS Employee";

   PayrollHeadWithNoFilters: Record "SwS Payroll Head";

   FileTempBlobOutStream: OutStream;

begin

   // Template for custom paycheck report

   if (pPayrollHead."Payroll No." = 0) or (pPayrollHead."Employee No." = '') then

       Error('No pay process found. Error code %1', 1005);

 

   Clear(CustomReport);

   CustomReport.SetTableView(PayrollHeadWithNoFilters);  // Set all user specific filters on DataItem back to empty

   CustomReport.UseRequestPage(false);

   CustomReport.SetReportParams(pReportParams);

   CustomReport.SetSinglePaycheckFilter(pPayrollHead."Payroll No.", pPayrollHead."Employee No.");

 

   Clear(FileTempBlobOutStream);

   pPaycheckTempBlob.Blob.CreateOutStream(FileTempBlobOutStream);

   CustomReport.SaveAs('', REPORTFORMAT::Pdf, FileTempBlobOutStream);

   Employee.Get(pPayrollHead."Employee No.");

   pDescription := 'Lohnabrechnung Custom';

end;

4.)Other sample codes for Subscriber events
 
First, all the recipients added are removed and then the recipients to receive the email are added.
The “pHandled” parameter only needs to be set if an email message is created in Event Subscriber.
If pHandled remains to be set to «false», then we just continue to work with the changed parameters and create the email.

 There is also theoretical possibility to adjust the email subject or text (body):
 [EventSubscriber(ObjectType::Codeunit, Codeunit::"SwS Mail", 'OnCreateMessageAuto', '', false, false)]

           local procedure HandleOnCreateMessageAuto(var pToRecipients: List of [Text]; var pSubject: Text; var pBody: Text; var pHandled: Boolean)

          begin

               pToRecipients.RemoveRange(1, pToRecipients.Count());

 

               pToRecipients.Add('max.muster@gmail.com');

               pToRecipients.Add('aziz.mulaj@swisssalary.ch');

           end;

 

 Since the same function is also used by the “Payslip PDF” report, the code would have to be adjusted a little

 if the recipients are not to be changed when emailing the payslip.

 

5.)Microsoft event publishers used to replace report calls
Microsoft only offers this publisher starting from version BC13.
If the partner wants to replace all wage accounting calls with the custom payslip, the publisher below by Microsoft can be used:
 
[EventSubscriber(ObjectType::Codeunit, Codeunit::ReportManagement, 'OnAfterSubstituteReport', '', false, false)]

local procedure HandleOnAfterSubstitueReport(ReportId: Integer; var NewReportId: Integer)

begin

   IF ReportId = REPORT::"SwS Paycheck" THEN

       NewReportId := REPORT::"SwS Custom Paycheck";

end;