Config / Development / Integration / ANVEDI Callback

ANVEDI Callback

The information on this page are for on-premise installations using the FOB files only.

If you’re using Microsoft Dynamics NAV 2017 or newer and Anveo EDI Connect 5.00 offers a new event based customization logic. We highly recommend moving to the new integration events, if possible, to make upgrades to newer versions easier.

The Codeunit ANVEDI Callback with the ID 5327310 is the central point if you want to change the behavior of Anveo EDI Connect. We keep the API of this Codeunit constant, so you don’t have to overwrite this object when you update our module. There are several functions that can be modified by you and some help functions that must not be modified. If you have updated the module and miss a help function that might have been added in a newer version, there is a second object called EDI Callback - Template with ID 5327313 where you will find the new functionality.

OnFunction

The module allows you to define your own functionality, which can be called from the EDI mappings. You can define as many functions, as you need. You should use the predefined case-statement and add calls to the build-in functions FunctionName..FunctionName5.

You should not put any code outside the predefined case-structure, as this function can be called quite often and any additional code may have negative performance impacts.

CASE TRUE OF
  // ... other functions

  FunctionName('EXAMPLE', 'HelloWorld'):
    BEGIN
      FunctionResult('Hello World!');
      EXIT;
    END;
END;
Example: “Hello World” function in OnFunction

The number at the end of the local helper function FunctionName defines the parameter count. You can define functions with up to five parameters. You can access the content of the parameters by calling the functions GetTextParameter(ParNumber) and the similar functions for other data types. The parameter number is counted from “1” to “5”.

Each function has to return a value by calling the local function with the name FunctionResult.

You should call the function FunctionResult only once. It is good practice to add an EXIT statement directly after it to prevent calling the function multiple times.

You can choose the object and function names as you wish.

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.

Here a complete list of the available functions to use in the CASE statement. As of Anveo EDI Connect 4.00:

  • FunctionName(ObjectName: Text; FunctionName: Text)
  • FunctionName1(ObjectName: Text; FunctionName: Text; ParamName1: Text)
  • FunctionName2(ObjectName: Text; FunctionName: Text; ParamName1: Text; ParamName2: Text)
  • FunctionName3(ObjectName: Text; FunctionName: Text; ParamName1: Text; ParamName2: Text; ParamName3: Text)
  • FunctionName4(ObjectName: Text; FunctionName: Text; ParamName1: Text; ParamName2: Text; ParamName3: Text; ParamName4: Text)
  • FunctionName5(ObjectName: Text; FunctionName: Text; ParamName1: Text; ParamName2: Text; ParamName3: Text; ParamName4: Text; ParamName5: Text)

Here a list of the function you can use to access the parameters:

  • GetTextParameter(ParNum : Integer) : Text
    • Gets the parameter and tries to cast it to data type text.
  • GetIntegerParameter(ParNum : Integer) : Integer
    • Gets the parameter and tries to cast it to data type integer.
  • GetBooleanParameter(ParNum : Integer) : Boolean
    • Gets the parameter and tries to cast it to data type boolean.
  • GetDecimalParameter(ParNum : Integer) : Decimal
    • Gets the parameter and tries to cast it to data type decimal.
  • GetDateParameter(ParNum : Integer) : Date
    • Gets the parameter and tries to cast it to data type date.
  • GetTimeParameter(ParNum : Integer) : Time
    • Gets the parameter and tries to cast it to data type time.
  • GetDateTimeParameter(ParNum : Integer) : DateTime
    • Gets the parameter and tries to cast it to data type date/time.
    • Gets the parameter as an instance of the Codeunit ANVEDI Variant.

CallbackRegistration

This function is called whenever something happens in the module, you can react to. The function contains a case structure, where you can check on the passed parameter CallbackSupport what happened.

You should not put any code outside the predefined case-structure, as this function can be called quite often and any additional code may have negative performance impacts.

This structure might look unusual to C/AL developers, but we can this way add functionality, without the need to update the ANVEDI Callback Codeunit.

The available events are defined by the Codeunit ANVEDI Callback Support. In the following sections we will discuss the available events.

OnJobCallback

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.

OnAcceptTransmission

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.

Parameters:

EDITransmission

A record from table EDI Transmission with the data that is known so far. The record is not yet written.

If you react to this event, you have to call the following function:

HandleAcceptTransmission(Result : Boolean;VAR EDITransmission : Record "ANVEDI Transmission")

Parameters:

Result

Whether to receive the transmission or not. The value True means that you want to receive the data, the value False that you want to ignore the transmission.

EDITransmission

You should pass the record from the OnAcceptTransmission call to this parameter.

CASE TRUE OF
  // ...
  CallbackSupport.OnAcceptTransmission(ANVEDITransmission):
    BEGIN
      // Ignore files with the name "FileList.txt"
      // Usually you also want to check the communication channel etc. to only run this for specific channels
      IF ANVEDITransmission."Tag 2" = 'FileList.txt' THEN BEGIN
        CallbackSupport.AcceptTransmission(FALSE. ANVEDITransmission);
      END ELSE BEGIN
        CallbackSupport.AcceptTransmission(TRUE. ANVEDITransmission);
      END;
    END;
  END;
END;
Example: OnAcceptTransmission

OnBeforeList

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.

Parameters:

EDICommunicationChannel

Specifies a data record of the EDI Communication Channel table for which new messages are to be searched.

This event does not require a call to another function as it does not support any return values.

OnAfterList

This code is called after the module has searched for new data.

Parameters:

EDICommunicationChannel

Specifies a data record of the EDI Communication Channel table.

This event does not require a call to another function as it does not support any return values.

OnBeforeReceive

This event is called before a transmission is retrieved.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnAfterReceive

This event is called after a transmission is received.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnBeforeArchive

This event is called before a transmission is archived.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnAfterArchive

This event is called after a transmission is archived.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnBeforeDelete

This event is called before a transmission is deleted.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnAfterDelete

This event is called after a transmission is deleted.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnBeforeSend

This event is called before a transmission is send.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

When reacting to this event you have to call the function:

HandleBeforeSendTransmission(Result, EDITransmission)
Result

Whether to send the transmission. The value True means that the transmission should be sent.

EDITransmission

The transmission that you got with the event call.

OnComposeMessage

This event is called when a transmission is composed.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

This event does not require a call to another function as it does not support any return values.

OnAfterSend

This event is called after a transmission is sent.

Parameters:

EDITransmission

Specifies a data record of the EDI Transmission table.

When reacting to this event you have to call the function:

HandleAfterSendTransmission(Result, EDITransmission)
Result

The result is currently ignored.

EDITransmission

The transmission that you got with the event call.

OnReplacePlaceholder

This function is called when a string is evaluated that can contain user-defined variables, such as a file name.

You can find an example below:

If Placeholder = 'MyNumber' THEN BEGIN
    IF EDILinkedDocument.FINDSET THEN REPEAT
      RecID := EDILinkedDocument."Record ID";
      IF (RecID.TABLENO = DATABASE::"EDI Document") THEN BEGIN
        RecRef.GET(EDILinkedDocument."Record ID");
        RecRef.SETTABLE(EDIDocument);
        CallbackSupport.HandleReplacePlaceholder(TRUE, EDIDocument."System Document No.");
        EXIT;
      END;
    UNTIL EDILinkedDocument.NEXT = 0;
  
    CallbackSupport.HandleReplacePlaceholder(FALSE, '');
  END ELSE BEGIN
    CallbackSupport.HandleReplacePlaceholder(FALSE, '');
  END;
Example code: OnReplacePlaceholder

Parameters:

Placeholder

The variable name between the curly brackets for which a value is searched.

When reacting to this event you should call the function:

CallbackSupport.HandleReplacePlaceholder(Result,Value)

Parameters:

Result

Whether you want to return a value. If you return True you should specify a value for the variable. You can override system variables.

Value

The value that should be used.

OnError

This event is called when an error occurs in the processing queue.

Parameters:

EDIProcessingQueue

An instance of the table EDI Processing Queue whose processing failed.

AfterProcess

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.

Parameters:

EDIProcessingQueue

An instance of the table EDI Processing Queue that was processed.

LookupLinkedDocument

This function is called from the linked document list, if the user want to open the card page. There are a few predefined pages in the module and we try to fallback to the default lookup page, in case this function returns False.

LookupLinkedDocument(RecRef: RecordRef) : Boolean
RecRef

The record for which the user wants to open the page.

Return value

A boolean value. Return the value True, if the page was opened by this function; False otherwise.

     CASE RecRef.NUMBER OF
       DATABASE::"Sales Header":
          BEGIN
            RecRef.SETTABLE(SalesHeader);
            PAGE.RUN(PAGE::"Sales Order", SalesHeader);
            EXIT(TRUE);
          END;
      END;
Example code: Open card page for sales-order

BeforeConvert

This function is called before a mapping is started. The call is inside the database transaction of the mapping. You can cancel the mapping execution, before the mapping has even started by returning the value True. In general we do not recommend to use this function. Is you want to call custom code, please use either the newer CallbackRegistration or the OnFunction functionality.

AfterConvert

This function is called after a mapping is finished successfully. The call is inside the database transaction of the mapping. In general we do not recommend to use this function. Is you want to call custom code, please use either the newer CallbackRegistration or the OnFunction functionality.

In Anveo EDI Connect 4.00 we added to events to the function CallbackRegistration called OnError and AfterProcess. Please use the new functionality, if possible.

Cross-References

You can define your own cross-reference logic. This functionality is called, when the cross-reference type is set to callback. Often times we recommend using mappings instead of custom callback code to make it easier to read the mappings. Custom cross-reference code is, from our point of view, harder to maintain.

ValidateCrossReferenceNumber

Check whether a external cross-reference number is valid.

this function is deprecated and should not be used.

GetInternalNo

Returns an internal number from an external one.

GetInternalNo(TableID: Integer; FieldNo: Integer; RelationTableID: Integer; RelationFieldNo: Integer; RelationTableView: Text[1024]; RelationTableViewPar1: Variant; VAR InternalNo: Code[20]; EDICrossReferenceType: Record 5327361; ExternalNo: Text[64]; EDIProject: Code[20]) : Boolean

GetExternalNo

Returns a external number from an internal one.

GetExternalNo(TableID: Integer; FieldNo: Integer; RelationTableID: Integer; RelationFieldNo: Integer; RelationTableView: Text[1024]; RelationTableViewPar1: Variant; InternalNo: Code[20]; EDICrossReferenceType: Record 5327361; VAR ExternalNo: Text[64]; EDIProject: Code[20]) : Boolean

UpdateCrossReference

Is called if the user tries to update a cross-reference.

UpdateCrossReference(TableID : Integer; FieldNo: Integer; RelationTableID: Integer; RelationFieldNo: Integer; RelationTableView: Text[1024]; RelationTableViewPar1: Variant; InternalNo: Code[20]; EDICrossReferenceType: Record 5327361; CrossReference: Text[64]; EDIProject : Code[20])

Deprecated Functions

The functionality below is only partly implemented and thus not secure. We recommend using the default security filters of Microsoft Dynamics NAV 2015 and leaving the two functions empty.

ApplyUserFilter

Allows you to filter the passed data in a way that the user can change the filter later on. The use of this function is not recommended anymore. The function might be removed in newer versions.

ApplySecurityFilter

Allows you to filter the data in a way that the filter cannot be changed by the user. This function is not called in all instances. The use of this function is not recommended anymore. The function might be removed in newer versions.

WordPress Cookie Notice by Real Cookie Banner