cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Dom_CMME
Level: Powered On

Form Submission - Update Row in Excel

Hi all,

 

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

 

CW Flow 1.JPGCW Flow 2.JPG

 

Thanks in advance to anyone who can help.

 

Dom

3 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

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.

 

  1. 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.
  2. 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.
    FormsResponse-4.png

  3. 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'])
    FormsResponse-5.png

  4. 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.
    FormsResponse-6.png

  5. 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.
    FormsResponse-7.png

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']

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

Also, bookmark this link and use it as a reference when learning about expressions https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language.
FormsResponse-8.png

 

Please do not hesitate to reach out if you have any questions.

Regards,

Fausto Capellan, Jr


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

 

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.

 

Regards,

Fausto Capellan, Jr


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Super User
Super User

Re: Form Submission - Update Row in Excel

@Dom_CMME 

 

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:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-...

 

Please try that and let me know.


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

16 REPLIES 16
Super User
Super User

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!

Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

 

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:

  1. For the trigger, use the same one you are using: Forms - When a new response is submitted
  2. 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']
    FormsResponse-1.png
  3. 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.
    FormsResponse-2.png

  4. 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.
    FormsResponse-3.png

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.

 

Regards,

Fausto Capellan, Jr


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


Community Support Team
Community Support Team

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME ,

 

Do you want to add a new response to an Excel table, and update an existing item with other questions to that row if it is already exists?

 

We do need nested Apply to each actions, but in the following way. Please check the following flow configuration for a reference.

 

Add the trigger “When a new response is submitted”.

 

Initialize variable, set its Name to ExistingItems, Type as Array.

 

Add action Get response details, select Response Id from the trigger. An Apply to each will be added automatically.

 

Within Apply to each, do the following actions:

>Add action List rows present in a table.

>Add Apply to each 2, select value from List rows present in a table.

  >>Within Apply to each2, add action Append to array variable, set value as dynamic content jobtitle.

>Under Apply to each2, add a Condition to check if the variable ExistingItems contain TaskName (dynamic content from the trigger).

  >>If yes, add Condition 2 to filter out the specific existing one to update it, the condition is set to TaskName is equal to jobtitle.

Note: an Apply to each3 will be added automatically here.

    >>>Under If yes of Condition2, Update a row with other questions.

 >>If no, add action Add a row into a table to create a new item.

1.PNG2.PNG

 

Best regards,

Mabel

 

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

Thanks for the response Brad, as you should have been able to tell from my original post, Flow input those nested applies of it's own accord (hence my apology for the state of the flow).

 

I am not a Flow power user, simply dabbling with new ways to use it. Unfortunately, your answer assumes I understand the full mechanism which I do not...

 

Thanks anyways.

Dom_CMME
Level: Powered On

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.

CW Flow 3 - Results of Update.JPG

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.

 

Thanks again for your help so far

Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME  

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 Smiley Happy

 

  1. 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.
  2. 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.
    FormsResponse-4.png

  3. 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'])
    FormsResponse-5.png


  4. 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.
    FormsResponse-6.png

  5. 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.
    FormsResponse-7.png

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

  1. The expression starts with the first() function. This function retrieves the first item in a collection (array). 
  2. 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']).
  3. The next part of the expression is ['resourceData']; this comes from the trigger.
  4. 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.
    FormsResponse-8.png


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

@faustocapellanj - I got an email confirming you had replied with content (minus the images) but it's not showing on this actual thread...

 

Any idea where I can find it?

 

Thanks again for the updated reply, once I can see it I'll review and effect the appropriate changes.

Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

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.

 

  1. 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.
  2. 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.
    FormsResponse-4.png

  3. 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'])
    FormsResponse-5.png

  4. 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.
    FormsResponse-6.png

  5. 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.
    FormsResponse-7.png

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']

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

Also, bookmark this link and use it as a reference when learning about expressions https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language.
FormsResponse-8.png

 

Please do not hesitate to reach out if you have any questions.

Regards,

Fausto Capellan, Jr


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

@faustocapellanj - thank you again, this is all really helpful and if i could send you a digital beer, you'd be getting a crate full!

 

So I've updated the flow in line with your latest guidance and the flow immediately failed when i submitted a form response. 

 

To confirm, i loaded my form and input answers to 4 mandatory questions including Case Reference (first submission 999, next 998).

I then went back into the form and sent 2 new submissions ensuring i changed some data, input some new data and matched my above Case Reference inputs.

The form entries are showing in the spreadsheet as new rows and the flow itself is failing so the existing rows are not being updated.

 

Here's what i got from the Flow error outputs:

 

CW Flow 4 Bad Request 1.JPGFirst partCW Flow 4 Bad Request 2.JPGSecond part

Here is the right hand error details from the flow failure screen:

 

CW Flow 4 Bad Request 3.JPG

 
I'm happy to try and pull together full screenshots of the entire flow i've created although these will be quite big images.
 
Looking forward to yet more valuable input, you've been amazing so far 🙂
Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

 

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.

 

Regards,

Fausto Capellan, Jr


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

HI @faustocapellanj ,

 

Made that change and similar issue, i even went as far as editing the column name in the spreadsheet to CaseReference as you suggested and i go the same error:

 

Syntax error at position 20 in 'CaseReference equals '999''.
inner exception: Syntax error at position 20 in 'CaseReference equals '999''.
clientRequestId: 4d246679-efc1-4431-a766-4ed64fea3545

 

Am i doing something wrong with writing this? should there be an expression to cover this or is writing plain English right for this?

 

Again, happy to show you full details of the Flow if you need it but it looks like this filter query is the problem.

 

Thanks again

Dom

Super User
Super User

Re: Form Submission - Update Row in Excel

@Dom_CMME 

 

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:

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-odata-query-operations-in-sharepoint-...

 

Please try that and let me know.


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


View solution in original post

Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

Hi @faustocapellanj 

 

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:

 

  1. 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.
  2. 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.

 

Thanks again for all your help

Dom

Super User
Super User

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME 

 

What do you mean by "adding a new row"? Are you using the Excel sheet that stores all the answers from the form?


Fausto Capellan, Jr


Did I answer your question? Mark my post as a solution! Did my response help? Please give it a thumbs up!

Proud to be a Flownaut!


Dom_CMME
Level: Powered On

Re: Form Submission - Update Row in Excel

@faustocapellanj - I am but i realised on my way into the office this morning that I should create a separate spreadsheet for the results update Flow.

 

It clicked in my head that this flow should be applied to a separate tracking document rather than trying to update the "master" spreadsheet that the form already updates.

 

Apologies for any confusion or apparent stupidity on my side, all part of the learning process I guess!

 

I'll revise my approach in line with this and use everything you've kindly provide me to start over.

 

I will come back to you if there are any further issues but i suspect the "problems" will go away now.

 

I'm unable to mark a specific answer of yours as the correct solution, do you know if it's possible to mark multiple responses as the answer?

 

Thanks again

Community Support Team
Community Support Team

Re: Form Submission - Update Row in Excel

Hi @Dom_CMME ,

 

You could mark multiple responses as answer, just click Accept as Solution for each answer that you want to mark.

 

Best regards,

Mabel

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 125 members 5,278 guests
Please welcome our newest community members: