In Anveo EDI Connect you can use custom codeunits to handle data exchange. You can choose to implement only the methods that you need and allow, for example, only sending of files.
Custom communication codeunits are supported on all version of our module. We will illustrate it based on a Dynamics Extension written in AL, but the same applies for the older development platforms.
Using a Custom Communication Handler
If your system has a custom communication handler, you’ll need it’s codeunit-ID to setup the communication channel . You can set it up as any integrated communication handler, but you’ll have to enter the Codeunit ID by hand. The lookup will not allow you to select your custom handler. Afterwards refresh the page and configure the channel, if neccessary by clicking on Configure .
Basic Requirements
Custom communication codeunit will get a special record “ANVEDI Format Control” from the module passed to the OnRun trigger. You’ll have to get the requested communication action from that record and call your code accordingly.
Example
codeunit 50000 "My Anveo File Handler"
{
TableNo = "ANVEDI Format Control";
trigger OnRun()
var
EDICommunicationChannel: Record "ANVEDI Communication Channel";
EDITransmission: Record "ANVEDI Transmission";
ProcessingQueue: Record "ANVEDI Processing Queue";
begin
ProcessingQueue.Get("Processing Queue Entry No.");
ProcessingQueue.TestField("Communication Channel");
EDICommunicationChannel.Get(ProcessingQueue."Communication Channel");
if Action in [Action::Receive, Action::Send, Action::Archive, Action::Delete] then begin
EDITransmission.Get(ProcessingQueue."Transmission Entry No.");
end;
case Action of
Action::Connect:
// Call your code to establish a connection
;
Action::Close:
// Your code to close a connection
;
Action::"Configure Comm.":
// Show configuration options
;
Action::"Receive/List":
ListFiles(EDICommunicationChannel);
Action::Receive:
ReceiveFile(EDICommunicationChannel, EDITransmission);
Action::Send:
SendFile(EDICommunicationChannel, EDITransmission);
Action::Archive:
ArchiveFile(EDICommunicationChannel, EDITransmission);
Action::Delete:
DeleteFile(EDICommunicationChannel, EDITransmission);
else
Error(NotSupportedErr);
end;
end;
var
NotSupportedErr: Label 'Not supported by communication codeunit.';
EDICommunicationMgmt: Codeunit "ANVEDI Communication Mgmt";
local procedure ListFiles(EDICommunicationChannel: Record "ANVEDI Communication Channel")
var
Transmission: Record "ANVEDI Transmission";
begin
// Create one transmission per message you want to import.
// We recommend to check the transmission table for the same comm. channel with the same "Tag 1" and "Tag 2"
// to prevent receiving the same message again, before inserting a new transmission
Transmission.Init;
Transmission."Entry No." := 0;
Transmission.Validate(Direction, Transmission.Direction::Incoming);
Transmission.Validate("Communication Channel Code", EDICommunicationChannel.Code);
Transmission.Validate(Description, 'Example file');
Transmission.Validate("Tag 1", 'Some data to identify');
Transmission.Validate("Tag 2", 'More data');
Transmission.Validate("Transmission Date/Time", CURRENTDATETIME);
EDICommunicationMgmt.InsertTransmissionAndReceive(EDICommunicationChannel, Transmission);
end;
local procedure ReceiveFile(EDICommunicationChannel: Record "ANVEDI Communication Channel";EDITransmission: Record "ANVEDI Transmission")
var
EDIMessage: Record "ANVEDI Message";
EDIProcessingQueue: Record "ANVEDI Processing Queue";
MessageFile: File;
InS: InStream;
OutS: OutStream;
begin
EDIMessage.Init;
EDIMessage.Validate("Transmission Entry No.", EDITransmission."Entry No.");
EDIMessage.CreateOutStream(OutS);
// Get the data and write it to OutS
EDIMessage.Insert(true);
// If you want to call archive afterwards:
EDIProcessingQueue."Processing Type" := EDIProcessingQueue."Processing Type"::Archive;
EDIProcessingQueue."Communication Channel" := EDICommunicationChannel.Code;
EDIProcessingQueue."Transmission Entry No." := EDITransmission."Entry No.";
EDIProcessingQueue.Insert(true);
// If you want to call delete afterwards
EDIProcessingQueue."Processing Type" := EDIProcessingQueue."Processing Type"::Delete;
EDIProcessingQueue."Communication Channel" := EDICommunicationChannel.Code;
EDIProcessingQueue."Transmission Entry No." := EDITransmission."Entry No.";
EDIProcessingQueue.Insert(true);
// Release the message
EDIMessage.Release();
end;
local procedure DeleteFile(EDICommunicationChannel: Record "ANVEDI Communication Channel";EDITransmission: Record "ANVEDI Transmission")
begin
// Your code here
end;
local procedure ArchiveFile(EDICommunicationChannel: Record "ANVEDI Communication Channel";EDITransmission: Record "ANVEDI Transmission")
begin
// Your code here
end;
local procedure SendFile(EDICommunicationChannel: Record "ANVEDI Communication Channel";EDITransmission: Record "ANVEDI Transmission")
var
EDIMessage: Record "ANVEDI Message";
InS: InStream;
begin
EDIMessage.SetRange(EDIMessage."Transmission Entry No.", EDITransmission."Entry No.");
if EDIMessage.FindSet then begin
repeat
if EDIMessage.CREATEINSTREAM(InS) then begin
// Send the data using the stream
end;
EDIMessage.CLOSE();
until EDIMessage.Next = 0;
end;
end;
}
Dependencies
If you want to create a custom communication handler in 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.