Business Integration Solutions documentation
How to: Create a Code Event / NETCode Event
A Code Event triggers 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 executes synchronously unless you enable Post with Job Queue. Use the job queue for processing BIS connections, it offloads processing to a new background session.
Differences 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 bound to a specific object, which was easy to access because the calling object type and ID were available. This metadata is no longer available in the new Code Event.
The advantage is that the Code Event has more flexibility. By using a unique ID, you can have several triggers in one object, each potentially triggering different connections at various stages in your code.
Prerequisites
The following prerequisites are required:
- Experience developing in Business Central AL.
- Familiarity with 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 setting up a Code Event
Open your app in VS Code.
Open the object where you want to trigger the code event from.
Create a dependency on BIS-Business Integration Solutions:
"dependencies": [ { "id": "9b0fdadc-3c4a-4dc4-82bf-6ac1c4bd5d71", "name": "BIS-Business Integration Solutions", "publisher": "STAEDEAN", "version": "20.0.0.0" } ],Declare the following local variables:
| Name | Datatype | Subtype |
|---|---|---|
| BISCodeEventAPI | codeunit | "BISAPI Code Event" |
| MyRecordRef | RecordRef |
Add one of the following 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 RecordReference):
RaiseEventForRecord(EventId: Code[50]; "RecordId": RecordId)For a record set:
RaiseEventForRecordSet(EventId: Code[50]; RecRef: RecordRef)For a record set with separate messages per record:
RaiseEvent(EventId: Code[50]; RecRef: RecordRef)
Steps for setting up a NETCode Event
Open your app in VS Code.
Open the object where you want to trigger the code event from.
Create a dependency on BIS-Business Integration Solutions:
"dependencies": [ { "id": "9b0fdadc-3c4a-4dc4-82bf-6ac1c4bd5d71", "name": "BIS-Business Integration Solutions", "publisher": "STAEDEAN", "version": "20.0.0.0" } ],Declare the following local variables:
| Name | Datatype | Subtype |
|---|---|---|
| BISCodeEventAPI | codeunit | "BIS Register Pipeline Event" |
| MyRecordRef | RecordRef |
Add one of the following events in your code to trigger the connection:
RegisterEventForRecord(RecRef: RecordRef)RegisterEvent(RecRef: RecordRef)RegisterEventForRecordSet(SenderObjectType: Text; SenderObjectId: Integer; RecRef: RecordRef)