Jun 08 2020 08:27 AM
How would I loop through multiple items in a SharePoint column to add a value in another column.
Example:
I have a Microsoft Form that is used as an order form and has an option for laptops. Once the form is filled in, it will trigger a Flow which adds the items to a SP list.
The problem is, if someone orders 2 laptops, it adds the items in an array in a column in the list. I have another column that I'm using to create the cost of the items. I am using an indexOf expression which to look for a value and then add that value to the new column. When there are multiple items chosen, it will only show the first items cost rather than adding them all together. Anyone any suggestions?
Jun 08 2020 11:01 AM - edited Jun 08 2020 02:51 PM
@timparsons the way I do this sort of thing is as follows and doesn't involve arrays. I have 2 lists, the main one for the orders and a second one that holds the unit cost for each item that might be ordered:
Following is the form:
The flow is then below. The trigger is When a new response is submitted and the first action is Get response details.
Next, add a SharePoint Get items gets the items from the UnitCost list:
Next add an Apply to each control and select value from the Get items section of the dynamic content. Next, add a Condition and in the left box select Title from the Get items section of the dynamic content is equal to then select Item from the Get response details section of the dynamic content.
Even though you would have asked for the quantity in your form, Forms nevertheless saves it as text. So add a Compose and add the following expression (in the Expression tab of the dynamic content box):
As you can see, the number ordered, their unit cost and the total cost are added into the SharePoint list:
Hope that helps.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
Jun 08 2020 12:29 PM
Jun 08 2020 12:48 PM
@timparsons yes the way I've done it they would need 1 form for however many laptops they wanted and a separate form for however many headsets etc. I'll post up the method for combining item types as soon as possible.
Rob
Los Gallardos
Microsoft Power Automate Community Super User