Please enable JavaScript to view this site.

 

OnBeforeExport Event 

Before the Export Process into Business Central is Run, this event will allow you to Skip the export process. 

Publisher

[IntegrationEvent(false, false)] 

procedure OnBeforeExport(var onBeforeExportHandler: Codeunit "Zde OnBefore Expenses Export")

begin

end;

 

Subscriber

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

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Expenses Customize", 'OnBeforeExport', '', true, true)] 

 

Zetadocs Expenses OnBeforeExport codeunit 

This codeunit exposes procedures that allow you to skip the export process, as well as giving access to the expenses export data. The following methods are currently available on instances of the OnBeforeExport data type. 

Method name 

Description 

SetIsToSkip (skipDefaultExport: Boolean)

Sets the value on whether to skip the expense export or not.

GetIsToSkip (): Boolean

Gets the currently set “Skip” value.

TryGetExportType (var exportType: Enum ZdeExportType): Boolean

Returns the Export Type for this expense.

TryGetExportDataCount (var exportCount: Integer): Boolean

Returns the number of Expenses in the Export.

TryGetExportDataFromExpense (var exportData: Codeunit "Zde Export Data Integration"; ExpensesIndex: Integer): Boolean

Returns the Expense Data specified by the index in the Export.

SetError (errorMessage: Text)

Allows setting of a custom error message.

Init()

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

Code Example


 

SetIsToSkip Method

Allows you to set the “Skip Export” value, if this is set to true then the Export will not happen. 

 

Syntax

onBeforeExportHandler.SetIsToSkip(true);

 

Parameters  

skipDefaultExport 

Type: Boolean 

Used to set whether to Skip the Export Process.

 

GetIsToSkip Method 

Provides a way to get the current “Skip Export” value.

 

Syntax

toSkip := onBeforeExportHandler.GetIsToSkip(); 

 

TryGetExportType Method 

Provides a way to get the Export Type for this Expense Export, i.e. whether it is a Journal or Purchase Invoice being generated. 

 

Syntax

onBeforeExportHandler.TryGetExportType(var exportType: Enum ZdeExportType) 

 

Parameter

exportType

Type: Enum ZdeExportType

Returns the Expenses Export Type of the Export.

 

TryGetExportDataCount Method 

Expense Exports can be constructed from multiple expenses, this method allows you to get a count of the expenses, use this in conjunction with the TryGetExportDataFromExpense method to retrieve an expense. 

 

Syntax

onBeforeExportHandler.TryGetExportDataCount(var exportCount: Integer); 

 

Parameter

exportCount 

Type: Integer 

The number of expenses held in the export data bundle. 

 

TryGetExportDataFromExpense Method 

Provides a way to retrieve the individual Expense Data from the Export Bundle, pass in the index of the expense to retrieve. 

 

Syntax

onBeforeExportHandler.TryGetExportDataFromExpense(var exportData1: Codeunit "Zde Export Data Integration"; ExpensesIndex2: Integer); 

 

Parameter1

exportData

Type: Codeunit "Zde Export Data Integration" 

This codeunit gives you read access to all the values in the expense retrieved. 

 

Parameter2

ExpensesIndex 

Type: Integer

Which expense to retrieve from the Bundle, the starting index is 0. 

 

SetError Method

Use this method to set custom error messages that will be populated in the Expense Report. 

 

Syntax

onBeforeExportHandler.SetError(errorMessage: Text); 

 

Parameter

errorMessage

Type: Text

The error message to display to the user in the Export Report.

 

 

Code Example

Below is an example of how to skip the Export Process depending on the type of export being performed, for Purchase Invoices the export is skipped, and for Journal it isn’t so an export will be created:

[EventSubscriber(ObjectType::Codeunit, Codeunit::"Zetadocs Expenses Customize", 'OnBeforeExport', '', true, true)] 

    procedureOnBeforeExport(varonBeforeExportHandler: Codeunit "ZdeOnBeforeExpensesExport") 

    var 

        ExportData: Codeunit "Zde Export Data Integration"; 

        ExportType: EnumZdeExportType

        ThisMethod: Text

    begin 

        ThisMethod := 'OnBeforeExport'

        //Want to skip the default export if its a journal 

        if (onBeforeExportHandler.TryGetExportType(ExportType)) thenbegin 

            caseExportTypeof 

                ZdeExportType::PurchaseInvoice

                    begin 

                        onBeforeExportHandler.SetIsToSkip(true); 

                    end

                ZdeExportType::Journal

                    begin 

                        onBeforeExportHandler.SetIsToSkip(false); 

                    end

            end

        end

    end