From version 1.7.0.0, the Shiptheory app raises an integration event each time Shiptheory updates a document in Business Central with shipping details: tracking number, carrier, carrier service, tracking URL and shipment cost. You can subscribe to these events from your own extension to run your own logic when tracking arrives, for example sending a dispatch notification. Each event gives you the record as it is now and as it was before the update, so you can tell exactly what changed.



Available events

There is one event per document type. Each is published on its own codeunit in the Shiptheory app.


  

DocumentCodeunit (ID)Event

Sales Shipment

SalesShipmentUpdate (73546586)

OnAfterSalesShipmentUpdated

Sales Invoice

SalesInvoiceUpdate (73546616)

OnAfterSalesInvoiceUpdated

Warehouse Shipment

WarehouseShipmentUpdate (73546638)

OnAfterWarehouseShipmentUpdated

Posted Warehouse Shipment

PostedWarehouseShipmentUpdate (73546661)

OnAfterPostedWhseShipmentUpdated


To use them, add the Shiptheory app as a dependency in your extension's app.json and download symbols. The events then appear in IntelliSense, with descriptions on hover.



Parameters

Every event passes two records of the document's header table:

  • The updated record (passed by var): the record as saved, including the values Shiptheory has just written.
  • The before-update record (prefixed x): a copy of the record exactly as it was in the database before this update.

Use the before-update record to detect changes, rather than xRec in the standard table events. For updates made from code, xRec usually already holds the new values.



Example

This subscriber runs when Shiptheory adds a tracking number to a Sales Shipment for the first time:

[EventSubscriber(ObjectType::Codeunit, Codeunit::SalesShipmentUpdate, 'OnAfterSalesShipmentUpdated', '', false, false)]
local procedure HandleTrackingAdded(var SalesShipmentHeader: Record "Sales Shipment Header"; xSalesShipmentHeader: Record "Sales Shipment Header")
begin
    if (xSalesShipmentHeader."Package Tracking No." = '') and (SalesShipmentHeader."Package Tracking No." <> '') then begin
        // Your logic here, e.g. send a dispatch notification
    end;
end;

The other events follow the same pattern with their own codeunit, event name and table.



Things to know

  • Shiptheory updates only. The events are raised when Shiptheory updates a document. They are not raised for edits made in the Business Central UI or by standard Business Central code.
  • Same transaction. Your subscriber runs in the same transaction as the update. If it raises an error, Shiptheory's update is rolled back and the request fails, so handle errors carefully or queue longer-running work.
  • The record is already saved. To save further changes to it, call Modify yourself. This raises the table's standard modify events again, and your codeunit needs Modify permission on the table, for example: Permissions = tabledata "Sales Shipment Header" = M;
  • Standard events still fire. The table's OnAfterModifyEvent is unchanged. It is raised with RunTrigger = false for Shiptheory updates.




If you encounter any issues, please feel free to contact our support team. You can call us on 0117 403 4313 (UK) / +1 (629) 666-6726 (US) or reach us online here.