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:
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.
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.
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.
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.
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.
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.
Code of the Business Transaction Type.
START_BT_WITH_REC
Starts a new business transaction for the given code and record id.
RUN_BT_BATCH_JOB
Runs the batch collection job with the specified name. This has to be called from inside a user transaction.
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.
RESET_TABLEVIEWS
Resets all existing stored table views. Has to be called from inside a user transaction.
SET_TABLEVIEW
Stores a table view under a specified name. Has to be called from inside a user transaction.
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.
The filter text in form of a Anveo EDI Connect table view. You should use the Microsoft Dynamics 365 Business Central 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.
RUN
Run one or more EDI mappings. Has to be called from inside a user transaction.
The code of the project or a filter string matching the project code.
The code of the mapping format or a filter string matching the format code.
The code of the mapping or a filter matching the desired mapping codes.
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.
Whether the post-processing should be executed. You normally want to set this to True.
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_FOLDER
Receives the data from the specified transmission folder or the folders. This function has to be called from inside a user transaction.
The code of the transmission filter or a filter string on the code field.
Whether the post-processing should be executed. You normally want to set this to True.
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.
The code of the communication channel or a filter string on the code field.
Whether the post-processing should be executed. You normally want to set this to True.
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.
Whether the post-processing should be executed. You normally want to set this to True.
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.
The code of the transmission folder or a filter string on the code field.
Whether the post-processing should be executed. You normally want to set this to True.
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.
The code of the communication channel or a filter string on the code field.
Whether the post-processing should be executed. You normally want to set this to True.
A filter on the post-processings. You can normally want to pass in am empty string.
PROCESS
Whether the post-processing should be executed. You normally want to set this to True.
A filter on the post-processings. You can normally want to pass in am empty string.
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.
The communication channel code.
SET_RECEIVER_PARTNER
Sets the receiver partner for the following mapping call inside the user transaction.
The receiver partner code.
SET_RECEIVER_IDENTIFICATION
Sets the receiver identification for the following mapping call inside the user transaction.
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.
The sender partner code.
SET_SENDER_IDENTIFICATION
Sets the sender identification for the following mapping call inside the user transaction.
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.
The error message. The execution will continue after this call. To break the control flow, use the native ERROR function.
LogWarning
Logs a warning.
The text of the warning.
LogInformation
Logs information.
The information to be logged.
LogDocumentError
Logs an error belonging to an EDI Document. There is a more universal function called LogRecIDErrorWithCode.
The error message.
The EDI Document the error belongs to.
LogDocumentWarning
Logs a warning belonging to an EDI Document. There is a more universal function called LogRecIDWarningWithCode.
The warning to be logged.
The EDI Document the error belongs to.
LogDocumentInformation
Logs an information belonging to an EDI Document. There is a more universal function called LogRecIDInformationWithCode.
The information to be logged.
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.
The error message to be logged.
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.
The warning that should be logged.
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.
The information to be logged.
The EDI Document Line the error belongs to.
LogErrorWithCode
Logs an error with an additional error code.
Whether to break the control flow or to continue with the execution
The error message to be logged.
A code to identify the error.
LogWarningWithCode
Logs a warning with an additional error code.
The warning that should be logged.
A code to identify the error.
LogInformationWithCode
Logs an information with an additional error code.
The information that should be logged.
A code to identify the error.
LogRecIDErrorWithCode
Logs an error message that should belong to a specific record.
Whether to break the control flow or continue the execution.
The error message to be logged.
The record ID the error belongs to.
An error code to identify the error.
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.
The warning that should be logged.
The record id the warning should belong to.
A code to identify the log entry.
LogRecIDInformationWithCode
Logs an information that should belong to a record.
The information that should be logged.
The record id the information should belong to.
A code to identify the log entry.