Form Submission - Update Row in Excel

I've seen a couple of posts similar but nothing that answers my specific need... apologies if this appears to be a duplicate.

I have built a form that submits data to an Excel sheet held in a Sharepoint team folder. This form has quite a few questions, only a few of which are relevant at the moment a user completes it. For example, it asks for a date of a 1st Held Appointment which can only be completed once this appointment has taken place. It also asks for the date of a 2nd Held Appontment but this takes place later down the line and the date needs to be submitted after that event.

I'm trying to build a Flow that acts as follows:

When form response is submitted

Check answer given to the question "Case Reference" (this is a field I have created and a user would complete with a unique number)

If the submitted "Case Reference" answer matches an existing row, add data from the other questions to that row

I can get it to do exactly this, but it adds a new row with the submitted data to the table as well as updating the existing row. I can only assume this is because the Form still carries out it's default action of creating a new row with the submitted form data as this action takes place before my flow runs? Is there any way to manage this process without preventing new row creation for genuine 1st submissions occur?

Here is my Flow (apologies for the messy layout, this is how the flow builder encapsulated when I added certain functions). I'm happy to rebuild from scratch if there's anyone with the know-how to make this work properly. Note that i have to use the "Formid" in all instances because flows NEVER detect my forms... sigh

Re: Form Submission - Update Row in Excel

Not sure what happened. I posted the reply and had to edit it to add another image. I reached out to the community manager to see what might have happened. I'm going to write the instructions again below.

For the trigger and the first action, keep the same ones from the previous post. I will explain the expression for the Forms - Get response details at the end of the post.

For the next step, add the action Excel Online (Business) - List rows present in a table. After you set the required parameters, click on Show advanced options and enter the Filter Query parameter as shown in the image below. This will only try to retrieve the row that contains that specific Case Reference from the submitted form.

For the next step, add a Condition, which will be used to check if the result from the Excel Online (Business) - List rows present in a table action contains a record. Since the Excel Online (Business) - List rows present in a table returns an array, even if it's just one item, we need to check by using the length() function. On the left side of the condition, enter the expression as shown below in both the line and the screenshot. Set the logical operation to is greater than, and then enter 0 on the right side of the condition.

length(body('List_rows_present_in_a_table')?['value'])

For the Yes branch, add an Excel Online (Business) - Update a row action. Flow will automatically wrap this action inside an Apply to each because of the array mentioned in step 3 above. Set your parameters as shown in the screenshot below.

And for the No branch, add an Excel Online (Business) - Add a row into a table. Set your parameters as shown in the screenshot below.

As for the expression in the Forms - Get response details action, this is how it's broken down:

the first() function is used to get the first element in an array or a string. The array for us is triggerBody()?['value']. By now, the expression should look like first(triggerBody()?['value']). Then to get the remaining part of the full expression, we can look at the Flow history and check out the OUTPUTS of the trigger. The image below indicates where ['resourceData'] and ['responseId'] can be found.

This is the final expression: first(triggerBody()?['value'])['resourceData']?['responseId']

Re: Form Submission - Update Row in Excel

Thanks for the update. Here's what you need to change: in the Filter Query, change Case Reference to Case_x0020_Reference. The Filter Query doesn't like columns with spaces, so if you can remove the space in your column name, then you can do CaseReference. Please try that and let me know.

Re: Form Submission - Update Row in Excel

You're using the word equals in your Filter Query. You have to use eq instead. Look at my screenshot for reference. Here's a link to documentation about SharePoint OData, which is the same for Excel or SQL since OData is something standard:

Re: Form Submission - Update Row in Excel

Your issue is the fact that you have nested apply to each loops. All of this could be done in a single apply to each.

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Re: Form Submission - Update Row in Excel

If you just need to retrieve the Forms entry submitted by the user and update the Excel row that contains that specific "Case Reference", you can take the approach outlined below:

For the trigger, use the same one you are using: Forms - When a new response is submitted.

For the next step, add the action: Forms - Get response details. Select the FormId from the dropdown, and for the ResponseId, enter the expression below in the Expression tab. The way this expression works is as follows: by wrapping the triggerBody()?['value'] inside the first() function, Flow will retrieve the first item from the trigger. To know exactly what to retrieve, we append ['resourceData']?['responseId'] outside the first() function.

first(triggerBody()?['value'])['resourceData']?['responseId']

For the next step, add the action: Excel Online (Business) - Get a row. Set all the parameters the same way you have them in your List rows present in a table action. For the Key Value field, select the Case Reference from the dynamic content window.

And for the final step, add the action: Excel Online (Business) - Update a row. Set all your parameters the same way you have them in your Update a row action.

For testing purposes, I only created a form and an Excel spreadsheet with three questions. You can adjust the Flow to fit the needs of your Forms and Excel spreadsheet. Please if you have any questions, do not hesitate to reach out.

Re: Form Submission - Update Row in Excel

@faustocapellanj Thank you for the comprehensive and descriptive response, it's very much appreciated.

I have done exactly what you've outlined and it works perfectly... except... the Form response still creates a brand new row in the Excel document as well as updating the existing row.

In this example, my first submission was:

Case Reference: 123456

Client Name: Test

Existing Client: No

Appointment Booked: 01/05/2019

Future Contact Date: 02/05/2019

I then did a second submission using the same form and submitted the following:

Case Reference: 123456

Client Name: Test Client

Existing Client: Yes

Appointment Booked: 02/05/2019

Future Contact Date: 03/05/2019

I need the form to submit new data to a new row when the "Case Reference" is unique (which it does).

I need the form to only update an existing row if the Case Reference matches one in the Excel document.

On a related note (and forgive my ignorance), would you be happy to loosely explain the way the expressions that you suggested work. I kind of understand parts of it but this language isn't one I have any real experience with.

Re: Form Submission - Update Row in Excel

It wasn't clear from your original post that you wanted to create a new row in the event the Case Reference is not found in the Excel spreadsheet, but if I missed that, my apologies. And since that's a requirement, I re-worked the Flow to suit those needs. I will add comments in the screenshots so you can understand better what's going on in each of the new actions I added to the Flow. This post may be a little long, so stay with me

From my previous post, I left the actions Forms - When a new response is submitted and Forms - Get response details and replace the remaining ones with the ones in the screenshots below.

For the next step, I added the action Excel Online (Business) - List rows present in table. I selected all the respective parameter for each field and then expanded the advanced options. In here, I added a Filter Query to retrieve the row that contains the Case Reference passed from the submitted form.

For the nex step, I added a Condition to check if the Excel row from the previous step exists. For the value to check on the left, I am using an expression to check the length of the array from the Excel Online (Business) - List rows present in table action. For the logical operator I am using is greater than and on the right side I am using 0. The expression and the screenshot below provides more information:

length(body('List_rows_present_in_a_table')?['value'])

In the Yes branch of the condition, I added an Excel Online (Business) - Update a row action, which Flow immediately wrapped inside an Apply to each because the date from the Excel Online (Business) - List rows present is considered an array, even if it only contains one item in it. I selected my respective parameters.

And in the No branch of the condition, I added an Excel Online (Business) - Add a row into a table, and selected my respective parameters.

As for the expression used in the Forms - Get response details, this is how it's broken down:

The expression starts with the first() function. This function retrieves the first item in a collection (array).

Inside the first() function, you can see the collection from the trigger: triggerBody()?['value']. You can see a reference to value in step 3 above. Here's out expression so far: first(triggerBody()?['value']).

The next part of the expression is ['resourceData']; this comes from the trigger.

And the last part of the expression is ['responseId'], which also comes from the trigger and it's part of the ['resourceData'] mentioned above. See the screenshot below for both ['resourceData'] and ['responseId'].You can find this information by looking at the Flow history.

Re: Form Submission - Update Row in Excel

Not sure what happened. I posted the reply and had to edit it to add another image. I reached out to the community manager to see what might have happened. I'm going to write the instructions again below.

For the trigger and the first action, keep the same ones from the previous post. I will explain the expression for the Forms - Get response details at the end of the post.

For the next step, add the action Excel Online (Business) - List rows present in a table. After you set the required parameters, click on Show advanced options and enter the Filter Query parameter as shown in the image below. This will only try to retrieve the row that contains that specific Case Reference from the submitted form.

For the next step, add a Condition, which will be used to check if the result from the Excel Online (Business) - List rows present in a table action contains a record. Since the Excel Online (Business) - List rows present in a table returns an array, even if it's just one item, we need to check by using the length() function. On the left side of the condition, enter the expression as shown below in both the line and the screenshot. Set the logical operation to is greater than, and then enter 0 on the right side of the condition.

length(body('List_rows_present_in_a_table')?['value'])

For the Yes branch, add an Excel Online (Business) - Update a row action. Flow will automatically wrap this action inside an Apply to each because of the array mentioned in step 3 above. Set your parameters as shown in the screenshot below.

And for the No branch, add an Excel Online (Business) - Add a row into a table. Set your parameters as shown in the screenshot below.

As for the expression in the Forms - Get response details action, this is how it's broken down:

the first() function is used to get the first element in an array or a string. The array for us is triggerBody()?['value']. By now, the expression should look like first(triggerBody()?['value']). Then to get the remaining part of the full expression, we can look at the Flow history and check out the OUTPUTS of the trigger. The image below indicates where ['resourceData'] and ['responseId'] can be found.

This is the final expression: first(triggerBody()?['value'])['resourceData']?['responseId']

Re: Form Submission - Update Row in Excel

Thanks for the update. Here's what you need to change: in the Filter Query, change Case Reference to Case_x0020_Reference. The Filter Query doesn't like columns with spaces, so if you can remove the space in your column name, then you can do CaseReference. Please try that and let me know.

Re: Form Submission - Update Row in Excel

You're using the word equals in your Filter Query. You have to use eq instead. Look at my screenshot for reference. Here's a link to documentation about SharePoint OData, which is the same for Excel or SQL since OData is something standard:

Re: Form Submission - Update Row in Excel

Apologies, i misread that particular screenshot in my haste to try and fix it!

So, better result now, it has indeed updated the existing row with the new data.

However, there are 2 issues:

In adding the new data, it blanks out any answers that are blank on the form so I lose exiting data. For example, on first submission i input a date into 2 of the form answers. I submit a new response with a matching CaseReference but leave the previous date fields blank and populate 2 different dates. It adds the new date to the existing row and then deletes the previous responses. It appears to be taking "blank" as a new answer which needs to be completed on the spreadsheet.

It's still adding a new row as well as updating the existing row. I suspect this is due to the form directly entering data into the spreadsheet. Is there any way to create a form and use Flow to connect it to a spreadsheet i create from scratch or am i stuck with the direct connection between the 2?

At this point i'm starting to think this is more hassle than it's worth. I'm filling in a business gap with this solution in lieu of a more robust solution that may appear in the next 6 months.

Do you have any further thoughts on why these problems persist and whether there is a viable solution without taking up too much more of your time?

I'm more than happy to supply the JSON export of the flow although i guess this won't be of much use outside our internal infrastructure.