> ## Documentation Index
> Fetch the complete documentation index at: https://docs.truststack.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Commissioning

> Commission events in the TrustStack.

In supply chains, it's common to record the moment when something is *first created, introduced* or *made traceable* - this could be:

* Harvesting grain from a paddock.
* Marking livestock for the first time.
* Manufacturing a batch of product (like cans of tuna, or pallets of flour)

In EPCIS, these creation moments are usually modeled using an `ObjectEvent` with:

* `action` set to `ADD`
* `epcList` or `quantityList` containing the identifier of the products that were created.
* and often accompanied by a `bizStep` like `commissioning` or `receiving` depending on context.

## Product Identifiers

At the end of a commissioning event, we need unique identifiers for the products that were created.
The TrustStack supports master data concepts such as [Trade Items](/master-data/trade-items).
As a refresh, a Trade Item is anything that can be priced in sold in a supply chain.

We can reference a `TradeItem` when creating a `Event` to generate a unique identifier for the product.

## Example

Let's say we are building a grain farm management application, and we need users to be able commission a batch of wheat.

Such as, *the farmer has harvested a paddock of wheat, and we need to create a unique identifier for the batch wheat*.

### Farm and Paddock

Let's use the TrustStack SDK to create a new `Farm` and `Paddock` for our example.

```typescript theme={null}
import {TrustStack} from "@truststack/sdk";

const truststack = new TrustStack({
  apiKey: "your-api-key",
});

const farm = await truststack.masterData.createFarm(
  {
    name: "Farm 1",
  },
  {organizationId: "farm-organization-id"}
);

const paddock = await truststack.masterData.createPaddock(
  {
    name: "Paddock 1",
    parentLocationId: farm.id,
  },
  {organizationId: "farm-organization-id"}
);
```

We now have a `Farm` and `Paddock` in the TrustStack for this farming enterprise.

### Wheat Trade Item

This farmer is harvesting **Wheat**, this can be priced and sold in the supply chain, so it is a `TradeItem`.

Let's create a `TradeItem` for **Wheat**.

```typescript theme={null}
const wheat = await truststack.masterData.createTradeItem(
  {
    name: "Wheat",
  },
  {organizationId: "farm-organization-id"}
);
```

### Harvest Event

Now, the farmer has harvested the wheat from the paddock, and we need to create an event to record this.

```typescript theme={null}
const harvestEvent = await truststack.event.createEvent(
  {
    action: "ADD",
    eventType: "OBJECT_EVENT",
    eventTime: new Date(),
    bizStep: "COMMISSIONING",
    disposition: "ACTIVE",
    readPoint: {
      location: paddock.id,
    },
    quantityList: [
      {
        tradeItem: wheat.id,
        quantity: 10000,
        unit: "KGM",
      },
    ],
  },
  {organizationId: "farm-organization-id"}
);

console.log(harvestEvent);
```

The output of this event will be:

```json theme={null}
{
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "eventTime": "2021-01-01T00:00:00.000Z",
  "eventType": "OBJECT_EVENT",
  "bizStep": "COMMISSIONING",
  "disposition": "ACTIVE",
  "readPoint": {
    "location": "<PADDOCK-ID>"
  },
  "quantityList": [
    {
      "tradeItem": "XXXX.1.1",
      "quantity": 10000,
      "unit": "KGM"
    }
  ]
}
```

An event has now been created:

* The `readPoint` is the paddock that the wheat was harvested from.
* The `quantityList` contains a batch/lot level identifier of the **Wheat** `TradeItem` that was harvested, and the quantity harvested.
* The `eventTime` is the date and time the harvest event occurred.
* The `bizStep` is the business step of the harvest event, in this case `COMMISSIONING`.
* The `disposition` is the disposition of the event, in this case `ACTIVE`.
