ANVEDI Events
Anveo EDI Connect offers a single codeunit for integration events: Codeunit ANVEDI Events. You can react to the events in this codeunit via you own codeunit. The events are supported in both the FOB and the Extension version of Microsoft Dynamics.
Events
The available Events are:
- OnFunctionRegistration
- OnFunctionExecution
- OnJob
- OnAcceptTransmission
- OnBeforeList
- OnAfterList
- OnBeforeReceive
- OnAfterReceive
- OnBeforeArchive
- OnAfterArchive
- OnBeforeDelete
- OnAfterDelete
- OnBeforeSend
- OnComposeMessage
- OnAfterSend
- OnReplacePlaceholder
- OnError
- OnAfterProcess
OnFunctionRegistration
procedure OnFunctionRegistration(Register: Codeunit "ANVEDI Function Register")
This event is called when the module searches for custom functions. You can define you own functions by using the functionality provided by the codeunit ANVEDI Function Register that is provided under the name Register. The codeunit provides two functions: RegisterFunction and AddParameter.
RegisterFunction expects two parameters, the object name and the function name of your new function. These names can be chosen freely, but may not exceed 30 characters.
The first 29 characters of the combination of object and function name needs to be unique to be able to specify the parameters from the mapping. You should try to keep the names short.
After registering a function you can call AddParameter up to 5 times. AddParameter expects a name for the parameter of your function. You can use multiple blocks of RegisterFunction and AddParameter in one Event. But we recommend to separate multiple functions to multiple Event listeners.
Register.RegisterFunction('CustomObj', 'MyFunction');
Register.AddParameter('Name');
Register.AddParameter('Value');
After registering the function, you have to react to function calls. This is done by the Event OnFunctionExecution described next.
OnFunctionExecution
procedure OnFunctionExecution(FunctionCall: Codeunit "ANVEDI Function Call")
The Event is called, when the module is searching fo a custom function implementation. An instance of the codeunit ANVEDI Function Call is passed to this event under the name FunctionCall.
You should check if the FunctionCall matches your custom function and only execute any code, if it does. This is done by calling the function Is() with the same parameters you have called RegisterFunction in the Event OnFunctionRegistration. If Is() returns true you can access the parameters, execute your custom code and return a value.
if FunctionCall.Is(ObjectNameTok, FunctionNameTok) then begin
Name := FunctionCall.GetTextParameter(1);
Val := FunctionCall.GetIntegerParameter(2);
Message(Name + ': ' + Format(Val));
FunctionCall.SetResult(TRUE);
end;
The codeunit ANVEDI Function Call provides the folowing functions:
procedure Is(ObjectName: Text[30];FunctionName: Text[30]): Boolean
Returns whether the function call matches the specified function signature.
procedure SetResult(Value: Variant)
You have to call this function to show the module that you have handled the function call. You can pass a function result, or just use true as the result.
procedure GetTextParameter(ParNum: Integer): Text[1024]
Retrieves a parameter with the given number as text. The index starts with 1.
procedure GetIntegerParameter(ParNum: Integer): Integer
Retrieves a parameter with the given number as integer. The index starts with 1.
procedure GetBooleanParameter(ParNum: Integer): Boolean
Retrieves a parameter with the given number as boolean. The index starts with 1.
procedure GetDecimalParameter(ParNum: Integer): Decimal
Retrieves a parameter with the given number as decimal. The index starts with 1.
procedure GetDateParameter(ParNum: Integer): Date
Retrieves a parameter with the given number as date. The index starts with 1.
procedure GetTimeParameter(ParNum: Integer): Time
Retrieves a parameter with the given number as date and time. The index starts with 1.
procedure GetDateTimeParameter(ParNum: Integer): DateTime
Retrieves a parameter with the given number as time. The index starts with 1.
procedure GetParameter(ParNum: Integer;var EDIVariant: Codeunit "ANVEDI Variant"): Boolean
Retrieves a parameter with the given number as EDIVariant. The function returns, whether the parameter could be retrieved. The index starts with 1.
OnJob
procedure OnJob(ParameterDictionary: Codeunit "ANVEDI Data Structures";EventArgs: Codeunit "ANVEDI Event Args")
You can use the job codeunit from the module to define custom jobs. The codeunit allows support the use of multiple parameters. You can find more information on the job handler documentation.
A dictionary containing the parameters passed to the job.
You should set the Event to handled, if you processed a job. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAcceptTransmission
procedure OnAcceptTransmission(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This function is called to determine whether a file or message should be accepted or ignored by the module. The module does not store whether a transmission was ignored and will call this function each time it sees a transmission. The file is not yet read, so you can only decide based on the available metadata.
The transmission, for which the metadata was retrieved. Please note that no data was received at this point of time and that the record is not yet inserted to the database.
You should set the Event to handled, if you processed the Event. You should also return a value whether to process the transmission (set the return value to true); or not (set it to false). The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnBeforeList
procedure OnBeforeList(EDICommunicationChannel: Record "ANVEDI Communication Channel";EventArgs: Codeunit "ANVEDI Event Args")
This code is called before the module looks for new data. This can be used to issue an external command or script to receive the files, before the module searches for new data.
The communication channel that should retrieve data.
You should set the Event to handled, if you processed the event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterList
procedure OnAfterList(EDICommunicationChannel: Record "ANVEDI Communication Channel";EventArgs: Codeunit "ANVEDI Event Args")
The communication channel that should retrieve data.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
This code is called after the module has searched for new data.
OnBeforeReceive
procedure OnBeforeReceive(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called before a transmission is retrieved. Please note that you cannot abort the processing at this point of time. If you want to decide whether to retrieve a message or not, please use the Event OnAcceptTransmission.
The transmission. The messages are not yet received.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterReceive
procedure OnAfterReceive(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called after a transmission is received.
The transmission after it was retrieved (you can access the messages).
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnBeforeArchive
procedure OnBeforeArchive(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called before a transmission is archived.
The transmission that is going to be archived on the remote location.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterArchive
procedure OnAfterArchive(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called after a transmission is archived.
The transmission that was archived on the remote location.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnBeforeDelete
procedure OnBeforeDelete(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called before a transmission is deleted.
The transmission that is going to be deleted on the remote location.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterDelete
procedure OnAfterDelete(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called after a transmission is deleted.
The transmission that was deleted from the remote location.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnBeforeSend
procedure OnBeforeSend(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called before a transmission is send.
The transmission that is going to be send.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnComposeMessage
procedure OnComposeMessage(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called when a transmission is composed.
The transmission that is composed.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterSend
procedure OnAfterSend(ANVEDITransmission: Record "ANVEDI Transmission";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called after a transmission is sent.
The transmission that was send.
You should set the Event to handled, if you processed the event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnReplacePlaceholder
procedure OnReplacePlaceholder(Placeholder: Text[50];var ANVEDILinkedDocument: Record "ANVEDI Linked Document";EventArgs: Codeunit "ANVEDI Event Args")
This function is called when a string is evaluated that can contain user-defined variables, such as a file name.
The name of the placeholder. The module is currently searching for a value to replace this specific placeholder. If you want to provide a value, you have to set specify the result and set the event to handled in the EventArgs.
A pre-filtered record of the linked documents. You can, for example, use this table to get the buffer documents that are contained in the file.
You should set the Event to handled, if you processed the Event. You also have to provide a value. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
The following example shows how you could return data from the linked document:
[EventSubscriber(ObjectType::Codeunit, Codeunit::"ANVEDI Events", 'OnReplacePlaceholder', '', TRUE, TRUE)]
local procedure OnReplacePlaceholderExternalDocumentNo(Placeholder: Text[50];var ANVEDILinkedDocument: Record "ANVEDI Linked Document";EventArgs: Codeunit "ANVEDI Event Args")
var
recID: RecordID;
ediDocument: Record "ANVEDI Document";
begin
if Placeholder = 'ExternalDocumentNo' then begin
if ANVEDILinkedDocument.FindSet() then
repeat
recID := ANVEDILinkedDocument.RecordId;
if recID.TableNo = Database::"ANVEDI Document" then begin
ediDocument.get(recID);
EventArgs.SetResult(ediDocument."External Document No.");
EventArgs.SetHandled(true);
exit;
end;
until ANVEDILinkedDocument.Next() = 0;
end;
end;
OnError
procedure OnError(ANVEDIProcessingQueue: Record "ANVEDI Processing Queue";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called when an error occurs in the processing queue.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
OnAfterProcess
procedure OnAfterProcess(ANVEDIProcessingQueue: Record "ANVEDI Processing Queue";EventArgs: Codeunit "ANVEDI Event Args")
This Event is called after the processing of an entry in the table EDI Processing Queue. You should check the status of the passed entry and react accordingly.
You should set the Event to handled, if you processed the Event. The description of the ANVEDI Event Args structure can be found at the end of this chapter.
ANVEDI Event Args
Some of the Events uses a structure called ANVEDI Event Args. This structure allows you to return values and to tell the module whether you have handled the event.
The following functions are available on the ANVEDI Event Args passed to the Event:
SetHandled(Value: Boolean)
Whether the Event was handled by you code.
SetResult(Value: Variant)
The return value, if the Event expects a return value.
Example
The following example shows, how you can add your own custom function “MYOBJECT.MYFUNC”, which shows a message containing the provided name followed by ‘: ‘ and the value. You can add as many functions from as many extensions, as you need.
codeunit 50100 MyAnveoFunctions
{
var
ObjectNameTok: label 'MYOBJECT';
FunctionNameTok: label 'MYFUNC';
[EventSubscriber(ObjectType::Codeunit, Codeunit::"ANVEDI Events", 'OnFunctionRegistration', '', TRUE, TRUE)]
local procedure OnRegisterFunctions(Register: Codeunit "ANVEDI Function Register")
begin
Register.RegisterFunction(ObjectNameTok, FunctionNameTok);
Register.AddParameter('Name');
Register.AddParameter('Value');
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"ANVEDI Events", 'OnFunctionExecution', '', TRUE, TRUE)]
local procedure OnFunction(FunctionCall: Codeunit "ANVEDI Function Call")
var
Name: Text;
Val: Integer;
begin
if FunctionCall.Is(ObjectNameTok, FunctionNameTok) then begin
Name := FunctionCall.GetTextParameter(1);
Val := FunctionCall.GetIntegerParameter(2);
Message(Name + ': ' + Format(Val));
FunctionCall.SetResult(TRUE);
end;
end;
}
Dependencies
If you want to react to the Event via AL, you need to add a dependency to the Anveo EDI Connect module.
The values for the OnPremise Extension are:
{
"id": "25286BD2-B08A-49F9-B613-64122CCEE4E1",
"name": "Anveo EDI Connect - OnPremise",
"publisher": "conion media GmbH",
"version": "5.x.y.z"
}
Please make sure, to replace x, y, z with the correct version number.
The values for the Business Central Online and Universal Code Extension are:
{
"id": "FC195C4F-19BF-4167-BFE8-6D1FF7D266BC",
"name": "Anveo EDI Connect",
"publisher": "conion media GmbH",
"version": "5.x.y.z"
}
Please make sure, to replace x, y, z with the correct version number. Older BC versions called “id” “appId”.