Skip to content

Enabling Automatic Dispatch for own Processes

Introduction

Document Dispatch enables the automatic dispatch of all Dispatch profiles when specific processes are executed (e.g., converting a contract into an order). Most relevant processes in the Business Central Standard are already covered. However it might be the case that whatever is supposed to trigger the sending is not covered yet or outside of the Business Central standard.

To achieve an integration within a desired procedure, you must:

  1. Define a custom event that is triggered at the desired point in your processes (e.g., after posting an order or updating a specific table).

  2. Ensure a connector exists which bridges your application/s with Document Dispatch. Create one if necessary to facilitate integration.

  3. Create an Event Subscriber for this event within your own connector.

This article explains how to implement these steps and provides example code for creating an event, subscribing to it, and linking it to our dispatch functionality.

Creating and Subscribing to a Custom Event

Step 1: Define the Custom Event

The first step is to define a custom event in the AL code. This event must be triggered at the appropriate point in the process to ensure the correct timing for dispatching. For example:

[IntegrationEvent(false, false)]
local procedure OnAfterCustomProcess(ParamCustomRecord: Record "Custom Table"; ParamAdditionalInfo: Text)
begin
    // This event will be triggered after a custom process, such as posting or updating.
end;

In this example, the OnAfterCustomProcess event is defined for a custom table. It takes the record of the table and any additional relevant information as parameters.

Step 2: Implement the Event Trigger

This custom event should be called at the point in the process where the dispatch should be initiated. For instance, if it should be sent after a record is posted:

procedure PostCustomRecord(var ParamCustomRecord: Record "Custom Table")
begin
    // Posting logic here...
    Commit();

    // Trigger the custom event
    OnAfterCustomProcess(ParamCustomRecord, 'Custom posting completed');
end;

Step 3: Create the Event Subscriber

Once the custom event is in place, the next step is to create an Event Subscriber in the connector that listens to the event and connects it to Document Dispatch:

[EventSubscriber(ObjectType::Codeunit, CodeunitId, 'OnAfterCustomProcess', '', false, false)]
local procedure HandleCustomProcess(ParamCustomRecord: Record "Custom Table"; ParamAdditionalInfo: Text)
var
    LocalRecordRef: RecordRef;
    LocalCodeunitSIMEDSQueueMgt: Codeunit "SIM_EDS Queue Mgt";
begin
    // Get the record reference for the custom table
    LocalRecordRef.GetTable(ParamCustomRecord);
    LocalRecordRef.SetRecFilter();

    // Call the dispatch functionality
    LocalCodeunitSIMEDSQueueMgt.SendEDS(LocalRecordRef, false, false, '');
end;

Step 4: Make sure that the Automatic Dispatch is enabled

To make sure that the automatic dispatch feature is enabled, follow these steps:

  1. Open Dispatch Profiles from the Setup menu in the ribbon bar and execute Dispatch Profiles.
  2. Press New to create a new dispatch profile.
  3. Enter the name you want in the Code field, then choose an Output Type and the Table for the profile.
  4. Apply the tab settings you like to use in the checkboxes beside it.
  5. Open Output Type Setup in the action bar, and enter the right settings for the respective output type.
  6. If the line is shown with the color Red, we could use the action Check Configuration to look at what needs to be filled to make the profile work.
  7. For the Automatic Sending you need to turn on Send when Converting/Posting.
  8. When the user posts an order from the respective table, Document Dispatch will automatically create a sending entry in the Document Dispatch queue with the type "Delayed". All entries with the type "Delayed" will be processed via the Document Dispatch job queue at the specified time.

Explanation

Custom Event:
- You should define own events, such as OnAfterCustomProcess, which should be triggered at the right point in your processes (e.g., after posting a record).
- This ensures full flexibility to integrate Document Dispatch with your custom workflows.

Event Subscriber:
- The subscriber listens to the custom event and connects it to our dispatch procedure.
- This must be implemented within your connector.

Connector:
- If no connector exists, you must create one to link your custom tables/procedures with Document Dispatch.

Logs and Troubleshooting

If the integration does not work as expected:
- Check Custom Event Triggering: Ensure the custom event is called at the appropriate point in the process.
- Check Logs: Logs will indicate issues, such as misconfigurations or missing connections between the event and the dispatch procedure.
- Verify Connector Setup: If the Event Subscriber is not working, ensure it is correctly implemented in a functioning connector.

Summary

By creating a custom event and an Event Subscriber within your connector, you can extend the Document Dispatch functionality to custom tables and processes. The flexibility to define where and how the event is triggered allows seamless integration with unique workflows.

If no connector exists, it must be created as a foundation for this integration. For additional assistance, refer to our support documentation or contact technical support.