Config / Development / Integration / ANVEDI Integration

ANVEDI Integration

The ANVEDI Integration codeunit contains all public API calls to the EDI module, you might want to call from your custom code. All functions in this codeunit are supposed to be used, if you directly want to start an EDI action by code.

General Concepts

In this section we will discuss the core concepts first, which you should understand to be able to read the code examples.

User Transactions

Anveo EDI Connect has a concept called “user transactions”, which can span multiple database transactions and collect multiple errors. Most actions in Anveo EDI Connect will require an open user transaction to run them. You can start a user transaction by calling:

// Start a new user transaction with the description given by TextDescription
ANVEDIIntegration.BEGIN_USER_TRANSACTION(TextDescription);

// Your EDI code

// End the user transaction and show an error list, if there were any
ANVEDIIntegration.END_USER_TRANSACTION(TRUE, FALSE);
Example: Starting a user transaction

The call to END_USER_TRANSACTION allows you to either show errors, break the current database transaction or get a return value, whether there was an error. We will discuss it in detail later.

BEGIN_USER_TRANSACTION

Starts a new user transaction. Please note that you only integrate calls in the EDI module at points where a COMMIT can take place. In many cases, the module will commit all database changes before executing the EDI logic. Also consider just marking the data and using a background job to execute the EDI logic.

The given text is shown to the user, if a waiting dialog is opened, because the process takes time.

BEGIN_USER_TRANSACTION(Text : Text[1024])

You should always terminate a call to BEGIN_USER_TRANSACTION with a call to END_USER_TRANSACTION.

SHOWDIALOGS

This function can be used to hide any EDI dialogs.

SHOWDIALOGS(ShowDialogs : Boolean)

The parameter specifies whether the dialogs are shown or not. A call to this function has to be inside a user transaction. You normally will call this function directly after BEGIN_USER_TRANSACTION.

ISPROCESSING

This function returns whether you are within a mapping execution. You can check this value when validating triggers, for example, to achieve a different behavior when processing EDI processes. You can also use this value to display input dialogs only when you are not processing EDI.

END_USER_TRANSACTION

This function will terminate a user transaction.

END_USER_TRANSACTION(ShowErrorList : Boolean; BreakOnError : Boolean) Success : Boolean
ShowErrorList

If there were errors during the transaction, show then in a dialog to the end-user. This parameter does not have any effect, if GUIALLOWED is False.

BreakOnError

Whether the module should throw an error, breaking the current process flow. All code after this line is not executed, if there was an error during the transaction. Setting this parameter to True will show an error messages that one or more errors occurred, if there were any. In this case the user cannot see the full list of errors.

Success

A return value, whether there was an error or not. Returns True on success, i.e. there were no errors; False otherwise.

The return value was named differently in older versions of the module, but had the same function. The old return value name was incorrect, the function always returned True on success.

Work with Business Transactions

RUN_BUSINESSTRANSACTION_JOB

Runs the data collection job of a specified business transaction type. This has to be called from inside a user transaction.

RUN_BUSINESSTRANSACTION_JOB(BusinessTransactionTypeCode : Code[20])
BusinessTransactionTypeCode

Code of the Business Transaction Type.

// Start a new user transaction with the description given by TextDescription
ANVEDIIntegration.BEGIN_USER_TRANSACTION(TextDescription);

// Collects the data of the Business Transaction Type "INVOICE_OUT" and processes the mappings
ANVEDIIntegration.RUN_BUSINESSTRANSACTION_JOB('INVOICE_OUT');

// End the user transaction and show an error list, if there were any
ANVEDIIntegration.END_USER_TRANSACTION(TRUE, FALSE);
Example: Run business transaction data collection job

START_BT_WITH_REC

Starts a new business transaction for the given code and record id.

START_BT_WITH_REC(BusinessTransactionTypeCode : Code[20];RecID : RecordID)

RUN_BT_BATCH_JOB

Runs the batch collection job with the specified name. This has to be called from inside a user transaction.

RUN_BT_BATCH_JOB(BatchCode : Code[20])

Actions

Sometimes you want to create a button on a page to start an EDI process, or you want to integrate it, for example, into the release process. For this cases you can run almost all actions of the module from code. Please keep in mind that EDI processes should usually be automated and running in the background. So before adding actions in code, consider the possibility of a background job as an alternative.

Run an EDI Mapping

To run an EDI Mapping we will need to start a user transaction. Afterwards we might want to pass data to the mapping. We can than run the mapping and check the result when we end the user transaction. You will find the detailed description of the commands after the code example.

// Start a new user transaction with the description given by TextDescription
ANVEDIIntegration.BEGIN_USER_TRANSACTION(TextDescription);

// Reset any existing table views
ANVEDIIntegration.RESET_TABLEVIEWS();

// Copy sales invoice header from Rec to a local variable
SalesInvoiceHeader := Rec;
// Filter the local variable to the current record
SalesInvoiceHeader.SETRECFILTER;
// Store the filter to the record under the name INVOICE
ANVEDIIntegration.SET_TABLEVIEW('INVOICE', SalesInvoiceHeader.GETVIEW(FALSE));

// Run the mapping EXAMPLE, NAV, INVOICE. You can access the invoice header, by adding the table and setting the filter to a named table view and enter INVOICE as the name. In general, you can pass as many filters as you need to the mapping.
ANVEDIIntegration.RUN('EXAMPLE', 'NAV', 'INVOICE', FALSE, TRUE, '');

// End the user transaction and show an error list, if there were any
ANVEDIIntegration.END_USER_TRANSACTION(TRUE, FALSE);
Code Example: Run a mapping to export an invoice

RESET_TABLEVIEWS

Resets all existing stored table views. Has to be called from inside a user transaction.

RESET_TABLEVIEWS()

SET_TABLEVIEW

Stores a table view under a specified name. Has to be called from inside a user transaction.

SET_TABLEVIEW(FilterName : Code[30];FilterText : Text[1024])
FilterName

A code representing the name of the filter. You will have to specify exactly the same name in the EDI Mapping to retrieve the filter.

FilterText

The filter text in form of a Anveo EDI Connect table view. You should use the Microsoft Dynamics NAV 2013R2 build-in function GETVIEW, if possible, to get the correctly formatted string.

GET_TABLEVIEW

Retrieves a stored filter. Has to be called from inside a user transaction.

GET_TABLEVIEW(FilterName : Code[30]) : Text[1024]

RUN

Run one or more EDI mappings. Has to be called from inside a user transaction.

RUN(ProjectFilter : Text[250];FormatFilter : Text[250];CodeFilter : Text[250];MultipleAllowed : Boolean;ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
ProjectFilter

The code of the project or a filter string matching the project code.

FormatFilter

The code of the mapping format or a filter string matching the format code.

CodeFilter

The code of the mapping or a filter matching the desired mapping codes.

MultipleAllowed

Whether multiple mappings should be executed in case a filter is specified. This is a safety feature, preventing you from running more than one mapping.

ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessingQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

Other Actions

RECEIVE_ALL

Deprecated function. You should avoid calling the general function and call one of the more specific ones below.

Receives all communication channels. This function has to be called from inside a user transaction.

RECEIVE_ALL(ProcessFollowing : Boolean;ProcessingQueueView : Text[250])

RECEIVE_FOLDER

Receives the data from the specified transmission folder or the folders. This function has to be called from inside a user transaction.

RECEIVE_FOLDER(TransmissionFolderCodeFilter : Text[250];ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
TransmissionFolderCodeFilter

The code of the transmission filter or a filter string on the code field.

ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

RECEIVE_COMMUNICATIONCHANNEL

Receives data from the specified communication channel. This function has to be called from inside a user transaction.

RECEIVE_COMMUNICATIONCHANNEL(CommunicationChannelCodeFilter : Text[250];ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
CommunicationChannelCodeFilter

The code of the communication channel or a filter string on the code field.

ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

SEND_ALL

Deprecated function. You should avoid calling the general function and call one of the more specific ones below.

Sends all communication channels. This function has to be called from inside a user transaction.

SEND_ALL(ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

SEND_FOLDER

Sends open transmissions of the specified transmission folder. This function has to be called from inside a user transaction.

SEND_FOLDER(TransmissionFolderCodeFilter : Text[250];ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
TransmissionFolderCodeFilter

The code of the transmission folder or a filter string on the code field.

ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

SEND_COMMUNICATIONCHANNEL

Sends open transmissions of the specified communication channel. This function has to be called from inside a user transaction.

SEND_COMMUNICATIONCHANNEL(CommunicationChannelCodeFilter : Text[250];ProcessFollowing : Boolean;ProcessingQueueView : Text[250])
CommunicationChannelCodeFilter

The code of the communication channel or a filter string on the code field.

ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

PROCESS

PROCESS(ProcessFollowing : Boolean;ProcessingQueueView : Text[250];UserTransactionFilter : Boolean)
ProcessFollowing

Whether the post-processing should be executed. You normally want to set this to True.

ProcessQueueView

A filter on the post-processings. You can normally want to pass in am empty string.

UserTransactionFilter

Whether only post-processings from the current user transaction should be processed.

Setting the Recipient / Sender

SET_COMMUNICATION_CHANNEL

Sets the communication channel for the following mapping call inside the user transaction.

SET_COMMUNICATION_CHANNEL(ChannelCode : Code[20])
ChannelCode

The communication channel code.

SET_RECEIVER_PARTNER

Sets the receiver partner for the following mapping call inside the user transaction.

SET_RECEIVER_PARTNER(ReceiverPartner : Code[20])
ReceiverPartner

The receiver partner code.

SET_RECEIVER_IDENTIFICATION

Sets the receiver identification for the following mapping call inside the user transaction.

SET_RECEIVER_IDENTIFICATION(Identification : Text[64])
Identification

The receiver identification. This is a free-text, which might have a special meaning on specific communication channels.

SET_SENDER_PARTNER

Sets the sender partner for the following mapping call inside the user transaction.

SET_SENDER_PARTNER(PartnerCode : Code[20])
PartnerCode

The sender partner code.

SET_SENDER_IDENTIFICATION

Sets the sender identification for the following mapping call inside the user transaction.

SET_SENDER_IDENTIFICATION(Identification : Text[64])
Identification

The receiver identification. This is a free-text, which might have a special meaning on specific communication channels.

Logging and Error Handling

The following functions can only be called while a mapping is running. These functions are meant to be used for custom error handlers from code.

LogError

Logs an error message.

LogError(ErrorMessage : Text[1024])
ErrorMessage

The error message. The execution will continue after this call. To break the control flow, use the native ERROR function.

LogWarning

Logs a warning.

LogWarning(WarningMessage : Text[1024])
WarningMessage

The text of the warning.

LogInformation

Logs information.

LogInformation(InformationMessage : Text[1024])
InformationMessage

The information to be logged.

LogDocumentError

Logs an error belonging to an EDI Document. There is a more universal function called LogRecIDErrorWithCode.

LogDocumentError(ErrorMessage : Text[1024];EDIDocument : Record "EDI Document")
ErrorMessage

The error message.

EDIDocument

The EDI Document the error belongs to.

LogDocumentWarning

Logs a warning belonging to an EDI Document. There is a more universal function called LogRecIDWarningWithCode.

LogDocumentWarning(WarningMessage : Text[1024];EDIDocument : Record "EDI Document")
WarningMessage

The warning to be logged.

EDIDocument

The EDI Document the error belongs to.

LogDocumentInformation

Logs an information belonging to an EDI Document. There is a more universal function called LogRecIDInformationWithCode.

LogDocumentInformation(InformationMessage : Text[1024];EDIDocument : Record "EDI Document")
InformationMessage

The information to be logged.

EDIDocument

The EDI Document the error belongs to.

LogDocumentLineError

Logs an error belonging to an EDI Document Line. There is a more general function called LogRecIDErrorWithCode.

LogDocumentLineError(ErrorMessage : Text[1024];EDIDocumentLine : Record "EDI Document Line")
ErrorMessage

The error message to be logged.

EDIDocumentLine

The EDI Document Line the error belongs to.

LogDocumentLineWarning

Logs a warning belonging to an EDI Document Line. There is a more general function called LogRecIDWarningWithCode.

LogDocumentLineWarning(WarningMessage : Text[1024];EDIDocumentLine : Record "EDI Document Line")
WarningMessage

The warning that should be logged.

EDIDocumentLine

The EDI Document Line the error belongs to.

LogDocumentLineInformation

Logs an information belonging to an EDI Document Line. There is a more general function called LogRecIDInformationWithCode.

LogDocumentLineInformation(InformationMessage : Text[1024];EDIDocumentLine : Record "EDI Document Line")
InformationMessage

The information to be logged.

EDIDocumentLine

The EDI Document Line the error belongs to.

LogErrorWithCode

Logs an error with an additional error code.

LogErrorWithCode(ContinueExecution : Boolean;ErrorMessage : Text[1024];Code : Code[20])
ContinueExecution

Whether to break the control flow or to continue with the execution

ErrorMessage

The error message to be logged.

Code

A code to identify the error.

LogWarningWithCode

Logs a warning with an additional error code.

LogWarningWithCode(WarningMessage : Text[1024];Code : Code[20])
WarningMessage

The warning that should be logged.

Code

A code to identify the error.

LogInformationWithCode

Logs an information with an additional error code.

LogInformationWithCode(InformationMessage : Text[1024];Code : Code[20])
InformationMessage

The information that should be logged.

Code

A code to identify the error.

LogRecIDErrorWithCode

Logs an error message that should belong to a specific record.

LogRecIDErrorWithCode(ContinueExecution : Boolean;ErrorMessage : Text[1024];RecID : RecordID;Code : Code[20];IsUserAcceptable : Boolean)
ContinueExecution

Whether to break the control flow or continue the execution.

ErrorMessage

The error message to be logged.

RecID

The record ID the error belongs to.

Code

An error code to identify the error.

IsUserAcceptable

Whether the error can be accepted by the end-user. This will require a non-empty error code.

LogRecIDWarningWithCode

Logs a warning that should belong to a record.

LogRecIDWarningWithCode(WarningMessage : Text[1024];RecID : RecordID;Code : Code[20])
WarningMessage

The warning that should be logged.

RecID

The record id the warning should belong to.

Code

A code to identify the log entry.

LogRecIDInformationWithCode

Logs an information that should belong to a record.

LogRecIDInformationWithCode(InformationMessage : Text[1024];RecID : RecordID;Code : Code[20])
InformationMessage

The information that should be logged.

RecID

The record id the information should belong to.

Code

A code to identify the log entry.

WordPress Cookie Notice by Real Cookie Banner