Forms to Sharepoint with Column conditions

Brass Contributor

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?

3 Replies

@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:

 

0-SP-List-Orders.png

 

0-SP-List-Orders-UnitCost.png

 

Following is the form:

1-Form.png

 

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:

 

2a-Flow-trigger-getResponse-getItems.png

 

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): 

int(body('Get_response_details')?['r4a70bd783b204c608871dd004c360add'])
you won't need to add the ID for the quantity question, just select it from the dynamic content tab and it will add the relevant question id.
 
Add another Compose and add the UnitCost column from the Get items section of the dynamic content box.
 
I always like Compose controls so add another one for the total cost where the expression will be a multiplication of the 2 previous Compose controls, i.e. UnitCost * Quantity:
mul(outputs('ComposeUnitCost'),outputs('ComposeQuantity'))
 
Finally we add the SharePoint Create item action and add in the outputs from the Compose controls and the other relevant fields.

 

2b-apply-Compose-Create.png

 

As you can see, the number ordered, their unit cost and the total cost are added into the SharePoint list:


0-SP-List-Orders.png

 

Hope that helps.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User

Thanks for that Rob. I'll have to try that out. How would they go about selecting more than one item - for example 2 headsets and 2 monitors? Would the user need to go through the form for each item?

@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