Extension Coding

You are here:

Most application development requires code to be written in Business Central. Communication between the device and Business Central is achieved via a codeunit responding to an event id (e.g., the “Run Event” block or a menu’s “Event ID” property).

This section provides an overview of how you can create a custom extension codeunit with some common examples. For more information or assistance with these concepts, contact Support.

Overview

You can subscribe to two primary Warehouse Insight events to handle customizations:

  • OnBeforeProcessEvent: fired before any base Warehouse Insight code is executed.
  • OnAfterProcessEvent: fired after any base Warehouse Insight code is executed.

A typical extension starting codeunit structure might look like the following:

OnBeforeProcessEvent

Most often the OnBeforeProcessEvent is the event you need to subscribe to and is primarily used for:

  • Handling a custom event request (e.g., Implementing new functionality or features)
  • Overriding a base Warehouse Insight event (e.g., Overriding the Purchase Order posting event)
  • Pre-processing a base Warehouse Insight event (e.g., Printing a document prior to the Purchase Order posting event firing)

The OnBeforeProcessEvent event has the following arguments:

  • piEventID: Integer (the ID of the event being triggered)
  • precEventParams: Record “IWX Event Param” (contains the context/variables being supplied to the event from the calling page; e.g., Line No., Document No., and Barcode data)
  • pbtxtOutput: BigText (populates with the results of the event handling; e.g., values, messages, and record sets)
  • pbOverrideWHI: Boolean (set to true if the event has been handled and no further base product processing required; must be set to true for custom events)

A typical structure for the event handler might look like this:

See the examples below for various code implementations. More examples can be found on the Knowledge Base or by contacting Support.

OnAfterProcessEvent

You only need to subscribe to OnAfterProcessEvent when you wish to have the base product event handling take place and when completed, perform additional work/changes.

The OnAfterProcessEvent event has the following arguments:

  • piEventID: Integer (the ID of the triggered event)
  • precEventParams: Record “IWX Event Param” (contains all the context/variables being supplied to the event from the calling page; e.g., Line No., Document No., and Barcode data)
  • pbtxtOutput: BigText (populated with the results of the event handling; e.g., values, messages, and record sets)

A typical structure for the event handler might look like this:

Example

The following examples illustrate common scenarios encountered with custom functions. The sample code is the bare minimum and does not include corresponding application designer/blocks that would be required/involved.

For examples on overriding or extending base Warehouse Insight events, consult the Knowledge Base or contact Support.

Executing an Internal Process

Executing procedures within Business Central without returning data is often required. This can be achieved by a menu setting the “Event ID” property or via the “Run Event” block; see the Device Menus page for more information.

Below is a sample implementation of an extension codeunit and application that logs the current user and (optionally) returns a message back to the device.

Returning a Single Value

Occasionally, applications need to retrieve a value from Business Central. This can be achieved via the “Run Event Set Value” block.

Below is a sample implementation of an extension codeunit and application that returns the current quantity on hand (Inventory) for a specific Item.

Returning Line Data

The grid and card views both require a dataset to display records. Building up the dataset required requires two parts:

  • Device Columns (configured per event)
  • Code to generate the data based on the defined columns and the supplied record.

Applications often only require a single source of information (lines); e.g., lookup lists, journal lines, and more.

Below is a sample implementation of an extension codeunit, application, and columns that return a list of Items.

Returning Header and Line Data

The grid and card views both require a dataset to display records. Building up the dataset required requires two parts:

  • Device Columns (configured per event)
  • Code to generate the data based on the defined columns and the supplied record.

Applications are often display document type data (e.g., Purchase Orders, Picks, and more). The process is similar to the Returning Line Data example except that additional columns need to be defined for the header, and the extension code is modified slightly to pass in the additional record.

Below is a sample implementation of an extension codeunit, application, and columns that return a purchase order.

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
Need help?

Leave A Comment

Go to Top