addMaterial()
Unless you use the createRecord() or copyRecord() functions to first create the item record for the material, you can only add items that already exist in the account.
The addMaterial() function (client-side) adds a material item to the configuration by including it in the SOLE/MATERIALS predefined answer, which represents the list of active materials. Users will see the material item under the corresponding section in the Audit menu on the product interface. If users create a work order for the configured item, the material will be included in that work order. For more information about materials, see Defining Materials for the Configurable Item.
A material added by this function is only available during the current processing flow. To keep the material in SOLE/MATERIALS, call addMaterial() in every processing flow. Each processing flow consists of the following steps: before-event actions run, building blocks are refreshed, after-event actions run. This processing flow repeats with every mouse click.
Syntax
Use this syntax for the addMaterial() function:
addMaterial({
itemid: string,
item: number | string,
qty: number | string,
colmap: {
key1: value1,
key2: value2,
key3: value3,
// Additional key-value pairs
}
});
Parameters
Either itemid or item is required.
The addMaterial() function accepts a single object as a parameter. The object includes the following properties:
-
itemid- The item name or number.Note:The
skuparameter was initially used to represent the item name or number. For new implementations, useitemidinstead ofsku. -
item- The item internal ID. -
qty- The number of items to add. If the quantity isn't provided, it defaults to 1. -
colmap(object) - Key-value pairs to set line fields on the work order.
Examples
The following examples show how to use the addMaterial() function.
Including a Material in the Configuration
This example shows how to include a material in a configuration.
addMaterial({
itemid: 'AB1-CHERRY-DESK-TOP',
qty: 1,
colmap: {
description: 'Cherry desktop for deluxe business desk'
}
});