<< Click to Display Table of Contents >>

Navigation:  Zetadocs SDK Guide > Zetadocs SDK API >


OnBeforeDelivery Event

Runs after the original attachment has been applied to the email, and before the email has been sent out.



[IntegrationEvent(false, false)]

procedure OnBeforeDelivery(var ZdOnBeforeDeliveryHandler: Codeunit "Zetadocs OnBeforeDelivery")





To subscribe to this event, you will need to decorate the subscriber method with the correct EventSubscriber attributes:

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Customize", 'OnBeforeDelivery', '', true, false)]


Zetadocs OnBeforeDelivery codeunit

This codeunit exposes procedures that allow you to modify the Emails sent by Zetadocs. The following methods are currently available on instances of the OnBeforeDelivery data type.


Method name


AddOrUpdateAdditionalAttachments (Text, Text, Text)

Add or Updates a reference to an additional file to be attached to an email, a reference to any stationary to be applied, and a document link value used to tie an additional attachment to a specific email attachment.

AddOrUpdateTemplateValue(Text, Text)

Adds or updates the template value for the specified key.

GetAdditionalAttachments(var Dictionary of [Text, Text])

Returns the current list of Additional Attachments to be sent with the email.

GetRecordIds(var List of [RecordId])

This method will get the list of records being emailed, if the email is a consolidated batch it will retrieve every record in the batch.

GetReports(var List of [Text])

Gets the list of reports sent with the Delivery.

GetSendingUserMethod(): Text

Get the user who ordered the Delivery action.

GetTemplateValues(var Dictionary of [Text, Text])

Gets the dictionary of key value pairs that will be applied to the document template.

RenameReport(Text, Text)

Rename the report file.

TrySearch(List of [recordId], List of [Dictionary of [Text, Text]): Boolean

Use this method to search for any related documents associated to the list of recordId’s given.


This method will propagate any errors raised in the event subscriber back to Zetadocs Capture and Delivery


This method can be used to send a custom error message to Zetadocs Capture and Delivery.

Init(Record "Zetadocs Send Result")

This method is called internally by the publisher, a call to this method will return an error.


AddOrUpdateAdditionalAttachments Method

Will take a link to a SharePoint Online file, optionally a link to a Stationary file, if the file link already exists it will update the stationary link, otherwise it will add these to the email being sent, and a final optional value is for the document link, which is used to link an additional attachment to a specific attachment, this is needed when using the Combine Documents option in Zetadocs.



OnBeforeDeliveryHandler.AddOrUpdateAdditionalAttachments(FileFullReference: Text, StationeryReference: Text, LinkedDocumentKey: Text);




Type: Text

A link to a file on SharePoint online, for example “https://condoso.microsoft.com/Sharepoint/File1.pdf”.


Type: Text (Optional)

Name of a file uploaded to the Templates folder via the Zetadocs Tempalte page.


Type: Text (Optional)

Document Number that the Additional Attachment belongs to, for example to link to Sales Order 1001, the value would be 1001.


AddOrUpdateTemplateValue Method

Adds or updates the template value for the specified key.



OnBeforeMsgDelivertHandler.AddOrUpdateTemplateValue(keyName: Text, value: Text);




Type: Text

The key that will be changed, it must match the key in the document template.


Type: Text

The value that will replace the key in the document template.


GetAdditionalAttachments Method

Get the dictionary of additional attachments to be applied to the email.



OnBeforeDeliveryHandler.GetAdditionalAttachments(var Attachments: Dictionary of [Text, Text]);




Type: Dictionary of [Text, Text]

The current instance of additional attachments and stationary files to be applied to the email.


GetRecordIds Method

The purpose of this method is to retrieve all the records that are being emailed, emails can be a single delivery (single record was selected), a batch delivery (multiple records were selected) for multiple customers or a consolidated batch (multiple records selected for the same customer). So, the email could contain multiple records, this method will retrieve the records dependant on the type of delivery. You can then use the output to search for related documents.



onBeforeDeliveryHandler.GetRecordIds(recordIds: List of [recordId]);




Type: List of [recordId]

The returned list of records selected for emailing.


GetReports Method

Get the list of Report file names to be applied to the email.



OnBeforeDeliveryHandler.GetReports(var Reports: List of [Text]);




Type: List of [Text]

The current filenames of the Reports to be attached to the email.


GetSendingUser Method

Get the user who ordered the Delivery action.



OnBeforeDeliveryHandler.GetSendingUser() sendingUser: Text





GetTemplateValues Method

Gets the dictionary of key value pairs that will be applied to the document template.



OnBeforeMsgDelivertHandler.GetTemplateValues(var templateValues: Dictionary of [Text, Text]);




Type: Dictionary of [Text, Text]

The dictionary of template key value pairs that have been added.


RenameReport Method

Rename the report file to be added to the email.



OnBeforeMsgDelivertHandler.RenameReport(oldName: Text; newName: Text);




Type: Text

Name of the report file to be renamed.



Type: Text

Name that should replace the previous name of the report file.


TrySearch Method

This method gives you the ability to retrieve the list of documents from SharePoint that are associated with the Business Central records. For performance reasons it is best to build up a list of Record Id then perform the search once.



OnBeforeDeliveryHandler.Search(recordIds: List of [recordId]; var searchResultDictionary: List of [Dictionary of [Text, Text]]) WasSearchSucess: Boolean




Type: List of [RecordId]

This list of Business Central records will be used to search for linked documents in SharePoint.


Type: List of [Dictionary of [Text, Text]]

You should iterate over the list to retrieve a further dictionary, containing the metadata for the related file. The currently available metadata is as follows:

Modified, FileName, Url, DocumentReference, DocumentType.


Return Value


Type: Boolean

Indicates if the search to SharePoint was successfull.



PropagateLastError Method

This method should be used to push errors that have been raised by Zetadocs Capture and Delivery to declare stop the process execution.





SetError Method

This method is used to pass any custom errors to Zetadocs.



OnBeforeDeliveryHander.SetError(errorText: Text);



Type: Text

The error message to pass to Zetadocs.


Init Method

Initialises the OnBeforeDelivery object with the relevant information. This will be done internally and is not for 3rd parties consumption.