Set item action in List
- Updated: 2024/07/01
Set item action in List
You can set an item at the specific position in a list and store the output in a variable using the Set item action.
Settings
- Select the list variable in which you want to set a value from the List variable list.
- Specify the position in the list where you want to set the item in the Index number field. The list index starts from 0. The first item in the list is at position 0, the second item at 1, and so on.
- Select a variable from the drop-down list in the Replace with field to replace the list variable.
- Select a variable that you want to use to store the output from the Assign the output to variable list.
Example of using Set item action in an automation
In this example, you will create an automation that sets an item at a specific position in a list and stores the output in a variable.
- Create a bot.
- On the left panel, click Automation.
A list of available bots and forms is displayed.
- Click Create a bot.
- Enter the bot name: List_Set_item.
- Click Create and Edit.
- On the left panel, click Automation.
- Create the user-defined variables using the Create variable
(+) icon at the top of the Variables menu. Create the
following variables and enter the values:
- Inventory_Stock (Type: List, Subtype: String)
- value at 0: Item ID: 1001, Product Name: Blue T-Shirt, Category: Apparel, Current Stock: 100, Reorder Threshold: 90, SupplierID: S001
- Value at 1: Item ID: 1002, Product Name: Running shoes, Category: Footwear, Current Stock: 95, Reorder Threshold: 60, SupplierID: S002
- Value at 2: Item ID: 1003, Product Name: Yoga Mat, Category: Fitness, Current Stock: 20, Reorder Threshold: 10, SupplierID: S003
- Value at 3: Item ID: 1004, Product Name: Coffee mug, Category: Housewares, Current Stock: 150, Reorder Threshold: 140, SupplierID: S004
- Value at 4: Item ID: 1005, Product Name: Backpack, Category: Accessories, Current Stock: 80, Reorder Threshold: 60, SupplierID: S005
- Updated_Inventory (Type: String)
Default value: Item ID: 1001, Product Name: Phone Case, Category:Accessories, Current Stock: 50, Reorder Threshold: 20, SupplierID: S006
- Inventory_Stock (Type: List, Subtype: String)
- To set a value at a specified position in a list, double-click or drag the action from the Actions pane.
- In the List variable field, select Inventory_Stock.
- In the Index number field, enter 0 to specify the position in the list you want to set a value.
- Select Updated_Inventory variable from the drop-down list in the Replace with field to replace the list variable.
- To store the output, select SampleString from the Assign the output to variable list field.
- Double click or drag Get item
action.
- In the List variable field, select Inventory_Stock.
- In the Index number field, enter 0 to specify the position in the list from where you want to retrieve a value.
- To store the output, select SampleString from the Assign the output to variable list field.
- To print the value, double-click or drag the Message box action. Select SampleString from the Enter the message to display field.
- Click Save and then Run.
The Updated_Inventory variable value (Item ID: 1001, Product Name: Phone Case, Category:Accessories, Current Stock: 50, Reorder Threshold: 20, SupplierID: S006) is set at Index 0 in the Inventory_Stock variable. When you use the Get item action to retrieve the value at index 0, on run time, the output is displayed as: