How to: Use the All items as a collection option
Use the All items as a collection option to perform an action on all items contained in a selected SmartObject. For example, a SmartObject contains a list of email addresses. As part of your workflow, you need to send an email to every address.
The All items as a collection option is located in the Smartfield Composer. When you drag a SmartObject Get List method from the Context Browser into a workflow step, the Smartfield Composer allows you to select the All items as a collection option from the drop down menu.
Example of the All items as a collection option
- Create a SmartObject as shown below. This Department Sales SmartObject stores department and total sales data.
- Once you create the SmartObject, populate it with some data by generating an editable list view.
- Create a new workflow called Sales.
- From the Toolbox, click the Basic category, and then drag the Send Email step onto the canvas.
- To select a recipient click the To drop down menu. By default, the workflow originator is selected. Other options in this drop down include Originator Manager, Browse, and Type/Construct my own. In this example, click the Add link and then select the Type/Construct my own option from the drop down menu.
- Configure the To field by dragging the Join function (found in the Text section) from the Context Browser into this field.
For more information on how to use the Smartfield Composer, see the Smartfield Composer topic.
- The Smartfield Composer shows. From the SmartObjects section, enter Department Sales in the search area to locate your SmartObject.
- Select the Department Sales SmartObject and then select the Get List option.
- Drag the Email property into the Values field. Change the name of the Join function to Department Email. Enter a semi-colon (;) into the Separator field. In this example, the Join function concatenates all email addresses with a semi-colon, which is then used to send the email.
- In the Get List Email SmartObject configuration block, select the All items as a collection option from the drop down menu.
- Click X to close the Smartfield Composer. The configuration on the To field is as follows:
- To add the average sales across all departments in the body of the email, drag the Average function from the Function section (found in the Mathematical section) from the Context Browser into this field.
- The Smartfield Composer shows. From the SmartObjects section, enter Department Sales in the search area to locate your SmartObject. Click the Department Sales SmartObject and select the Get List option. Drag the Total Sales property into the Values field. Change the name of the Average function to Average Sales. In this example, the Average function calculates the average total sales across all departments.
- In the Get List Total Sales SmartObject configuration block, select the All items as a collection option from the drop down menu.
- Click X to close the Smartfield Composer. The configuration in the email body is as follows:
- Deploy the workflow.
For more information on deploying the workflow, see the Deploy a Workflow topic.
- From K2 Management, start an instance of the workflow. At runtime, the workflow calls the SmartObject, collects and calculates data, and then sends an email every address. In this example, the body of the email contains the average sales figure across departments which is 11833.33.
The example below uses a SmartObject called Department Sales . The data stores names and email addresses for each of the department heads as well as total sales amount per department. In the workflow scenario, an email is sent to all department heads using the Send Email step. This email contains the average sales figure across all departments.