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:
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
Thanks in advance to anyone who can help.
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!
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 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.
Fausto Capellan, Jr
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.
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...
@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.
Thanks again for your help so far
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
As for the expression used in the Forms - Get response details, this is how it's broken down:
@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.
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.
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']
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.
Please do not hesitate to reach out if you have any questions.
Fausto Capellan, Jr
@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:
Here is the right hand error details from the flow failure screen:
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.
Fausto Capellan, Jr
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''.
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.
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:
Please try that and let me know.
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:
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
@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?
Hi @Dom_CMME ,
You could mark multiple responses as answer, just click Accept as Solution for each answer that you want to mark.