Business Integration Solutions Documentation

How To: Create a Code Event/NETCode Event

A Code Event is triggered from a Dynamics Business central Object and starts a pipeline for one or more records.

Usage

Use this task when you want to start a BIS Connection for a certain record from a specific object.

The Code Event is executed in a synchronious manner unless the property Post with Job Queue is enabled. It is recommended to use the Job Queue for processing BIS connections since this will offload processing to a new background session

Changes between Code Event and NETCode Event

The Code Event is rewritten to support similar functionality, while handling the loss of metadata access during a call. In the NETCode Event version of BIS, the setup was bound to a specific object, which was easy to access, since the calling object type and ID were available. This metadata is no longer available in the new Code Event.

The upside to this, is that the Code Event will have more flexibility. By using a unique ID, you can have multiple triggers in one object, all potentially triggering different connections at various stages in your code.

Prerequisites

The following prerequisites are required

  • Experience in developing in Business Central AL
  • Familiarity with the concept of Event based programming
  • Understanding of Business Integration Solutions and the role of Events in the pipeline
  • A valid developer license
  • An environment with Staedean-Common and BIS-Business Integration Solutions installed.

Steps for seting up a Code Event

  1. Open your app in VSCode
  2. Open the object where you would like to trigger the code-event from
  3. Create a dependency on BIS-Business Integration Solutions, which should be similar to this:
    "dependencies":  [
        {
            "id": "9b0fdadc-3c4a-4dc4-82bf-6ac1c4bd5d71",
            "name": "BIS-Business Integration Solutions",
            "publisher": "STAEDEAN",
            "version": "20.0.0.0"
        }
    ],
  1. Declare the following local variables:
Name Datatype Subtype
BISCodeEventAPI codeunit "BISAPI Code Event"
MyRecordRef RecordRef
  1. Add one of the 3 events in your code to trigger the connection For a Single Record
RaiseEventForRecord(EventId: Code[50]; RecRef: RecordRef)

For a RecordID (as an alternative to the RecordReference)

RaiseEventForRecord(EventId: Code[50]; "RecordId": RecordId)

For a recordSet

RaiseEventForRecordSet(EventId: Code[50]; RecRef: RecordRef)

For a recordset, but with separate messages per record

RaiseEvent(EventId: Code[50]; RecRef: RecordRef)

Steps for setting up a NETCode Event

  1. Open your app in VSCode
  2. Open the object where you would like to trigger the code-event from
  3. Create a dependency on BIS-Business Integration Solutions, which should be similar to this:
    "dependencies":  [
        {
            "id": "9b0fdadc-3c4a-4dc4-82bf-6ac1c4bd5d71",
            "name": "BIS-Business Integration Solutions",
            "publisher": "STAEDEAN",
            "version": "20.0.0.0"
        }
    ],
  1. Declare the following local variables:
Name Datatype Subtype
BISCodeEventAPI codeunit "BIS Register Pipeline Event"
MyRecordRef RecordRef
  1. Add one of the 3 events in your code to trigger the connection
RegisterEventForRecord(RecRef: RecordRef)
RegisterEvent(RecRef: RecordRef)
RegisterEventForRecordSet(SenderObjectType: Text; SenderObjectId: Integer; RecRef: RecordRef)

The NETCode Event is available only for OnPremise environments, and it is marked as obsolete. Please consider switching to the Code Event in your connections.