--- title: "Calculate aggregate number of packages" slug: "cmn-calculate-aggregate-number-of-packages-actor" status: "update" updated: 2026-11-26T14:47:23Z published: 2026-11-26T14:47:23Z canonical: "docs.lobstersoftware.com/cmn-calculate-aggregate-number-of-packages-actor" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lobstersoftware.com/llms.txt > Use this file to discover all available pages before exploring further. # Calculate aggregate number of packages > [!NOTE] > Event action – Abstract > > **Purpose:** Populates the fields for "Aggregate number of packages" across line item levels of all or selected line item types in a general business object and optionally (additionally) summarizes the "Number of packages" of the direct line items as on the header level. > > > [!TIP] > > Tooltip > > > > - **Usage:** The event action must be executed with a common business object as the *reference object*. The calculation optionally takes into account *selected* or *all* **Line item types**. Depending on the **Calculate summary** option, the "Number of packages" in the header level is also updated. > > - **Parameter:** > > - The *optional* multiple selection for **Line item types** defines line item types for which the "Aggregate number of packages" should be calculated. By default (without a selection), the "Aggregate number of packages" is updated in line items of all types. > > - The **Calculate summary** option defines whether the sum over the "Number of packages" of the direct line items of all relevant **Line item types** should be assigned to the "Number of packages" field in the header of the common business object. > > - **Output:** > > - Updates the "Aggregate number of packages" field of all relevant **Line item types**. > > - *Optional*: Updates the "Number of packages" in the header level as a summary over the "Number of packages" in direct line items of the relevant **Line item types**. ![images/download/attachments/78252867/image2021-7-29_16-26-47-version-1-modificationdate-1627568810494-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2021-7-29_16-26-47-version-1-modificationdate-1627568810494-api-v2.png) The event action [Calculate aggregate number of packages](/v1/docs/en/cmn-calculate-aggregate-number-of-packages-actor) performs the following steps for all or selected **Line item types** (see [Line item type](/v1/docs/en/base-line-item-type)) in a *reference object* of the [Common business object](/v1/docs/en/orchestration-common-bto) type: 1. Within the line item hierarchy for each relevant [Line item type](/v1/docs/en/base-line-item-type), the field "Number of packages" (`numberOfPackages`) is assigned the value 1 for each line item if it is empty or filled with 0. 2. Within the line item hierarchy for each relevant [Line item type](/v1/docs/en/base-line-item-type), the field "AggregateNumberOfPackages" (`aggregateNumberOfPackages`) is filled for each line item according to the procedure described in the section "Calculation logic". 3. If the option **Calculate summary** is selected (default), then the total is additionally calculated via the field "Number of packages" (`numberOfPackages`) in all direct line items for all relevant **Line item types**. 4. This total number is assigned to the field "Number of packages" (`numberOfPackages`) of the *reference object*. **Runtime example:** The following screenshot shows schematically the effect per step within a multi-level line item hierarchy on the basis of a simple Input form for a fictitious [Common business object](/v1/docs/en/orchestration-common-bto) of the type "Package deal" (PACKAGE_DEAL): ![images/download/attachments/78252867/image2021-7-30_11-32-7-version-1-modificationdate-1627637529069-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2021-7-30_11-32-7-version-1-modificationdate-1627637529069-api-v2.png) - In step 1, the default value 1 for the **Number of packages** is added for "incomplete" items to prepare the subsequent steps. - In step 2, the **Aggregate number of packages** is calculated and assigned for each relevant item. - In step 3, the **Number of packages** is summarized for the direct line items. - In step 4, the "summary" from step 3 is assigned to the **Number of packages** in the header data of the *reference* *object*. > [!NOTE] > **NOTE:** > > The visualized calculations and assignments take place, of course, completely independently of the representation of the elements concerned in an input form. They directly affect the volatile data of the *reference* *object*, which is not saved by the event action. ## Calculation logic Within the line item hierarchy for each of the selected **Line item types**, the "Number of packages" (`numberOfPackages`) of each parent line item is taken as a *scalar* for the "Number of packages" of each direct or indirect child line item. - For top-level line items, the "Aggregate number of packages" (`aggregateNumberOfPackages`) is taken directly from the "Number of packages" (`numberOfPackages`). - For a child item, the "Aggregate number of packages" (`aggregateNumberOfPackages`) is calculated as the product of "Number of packages" (`numberOfPackages`) of the child item with "Aggregate number of packages" (`aggregateNumberOfPackages`) of the parent item. - This scheme is applied within a multi-level hierarchy from top to bottom over all levels, so that with each step in the hierarchy an additional scalar is added as a factor in the multiplication. **Example:** | Line item hierarchy | Goods description | Number of packages | Calculation | Aggregate number of packages | | --- | --- | --- | --- | --- | | 1 | Mixed pallet of beer | 2 | = | 2 Packages (pallets) | | └ | 1.1 | Crate of beer (Lager) | 30 | 2 x 30 = | 60 Packages (crates) | | └ | 1.1.1 | Bottle of beer (Lager) | 20 | (2 x 30) x 20 = | 1200 Packages (bottles) | | └ | 1.2 | Crate of beer (Celebr8or) | 6 | 2 x 6 = | 12 Packages (crates) | | └ | 1.2.1 | Bottle of beer (Celebr8or) | 24 | (2 x 6) x 24 = | 288 Packages (bottles) | | └ | 1.1.2 | Beach towel "Celebr8or" | 1 | (2 x 6) x 1 = | 24 Packages (beach towel) | | 2 | Float "Celebr8or" | 3 | = | 3 Packages (float) | | *Calculate total (optional)* | *5 Packages* | *∑* = 2 + 3 | ## Configuration ![images/download/attachments/78252867/image2021-7-29_16-37-49-version-1-modificationdate-1627569472258-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2021-7-29_16-37-49-version-1-modificationdate-1627569472258-api-v2.png) The event action [Calculate aggregate number of packages](/v1/docs/en/cmn-calculate-aggregate-number-of-packages-actor) expects a [Common business object](/v1/docs/en/orchestration-common-bto) as the *reference* *object*. In the context of another object type, the event action has no effect without an error occurring at runtime. The **Calculate summary** option (set by default) controls whether the "Number of packages" field in the *reference* *object* header data should be updated based on the information for [Direct line items](/v1/docs/en/base-get-line-items-resolver) of the relevant **Line item types**. - Without this option, step 3 and step 4 (see flowchart/runtime example above) are omitted without replacement. Multiple selection for **Line item types** can be used to define a positive list for *relevant* **Line item types** (see [Line item type](/v1/docs/en/base-line-item-type)). - If no **Line item types** are selected, all line items in the *reference* *object* are evaluated regardless of the [Line item type](/v1/docs/en/base-line-item-type). **Example:** In accordance with the runtime example (above), the event action [Calculate aggregate number of packages](/v1/docs/en/cmn-calculate-aggregate-number-of-packages-actor) for the displayed *reference object* is executed within a data input form for a fictitious [Common business object](/v1/docs/en/orchestration-common-bto) of the "Package deal" (`PACKAGE_DEAL`) type by clicking on a [Button](/v1/docs/en/fre-button-vo). | For the [Button](/v1/docs/en/fre-button-vo), a behavior is created with a [Client Workflow](/v1/docs/en/frebehav-client-workflow) behavior type, which is configured as shown on the right: - The **Validating rule** uses a [Check type](/v1/docs/en/core-check-type-rule) to ensure that the *reference* *object* is a [Common business object](/v1/docs/en/orchestration-common-bto). - As the only **Action on passed rule**, the event action [Calculate aggregate number of packages](/v1/docs/en/cmn-calculate-aggregate-number-of-packages-actor) (for the [Common business object](/v1/docs/en/orchestration-common-bto)) is added. The default configuration (all **Line item types** and **Calculate** **summary** option) can be kept here. **NOTE:** If the calculations are triggered not only manually but also, for example, automatically when saving, an event handling can be configured instead of the [Client Workflow](/v1/docs/en/frebehav-client-workflow), which then has to be addressed by the [Button](/v1/docs/en/fre-button-vo) via a [Custom action event](/v1/docs/en/core-custom-action-events). | ![images/download/attachments/78252867/image2021-7-29_16-40-36-version-1-modificationdate-1627569639453-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2021-7-29_16-40-36-version-1-modificationdate-1627569639453-api-v2.png) | | --- | --- | **Runtime example:** Based on the entries in the input form shown in the previous runtime example (above), the following image results after clicking the button: ![images/download/attachments/78252867/image2021-7-30_11-33-35-version-1-modificationdate-1627637617508-api-v2.png](https://cdn.document360.io/4be90b94-ec83-41d8-963e-962df16110d4/Images/Documentation/image2021-7-30_11-33-35-version-1-modificationdate-1627637617508-api-v2.png) - In items 2.1 and 3, the value 1 for **Number of packages** has been added. - The **Aggregrate number of packages** was calculated and assigned for all line items. - The **Number of packages** in the header data has been calculated and assigned. An input form is used to enter, view, and edit entity data. Examples of entities include purchase orders and shipments. Users create input forms in the form designer. When opened, the form automatically loads the associated data. ## Related - [Calculate aggregate number of packages (Order)](/ord-calculate-aggregate-number-of-packages-actor.md) - [Calculate aggregate number of packages (Shipment)](/shp-calculate-aggregate-number-of-packages-actor.md)