“My Power Automate flow fails when users don’t upload an attachment, how do I modify it to save Forms data even when there’re no attachments?”
You can collect various pieces of information via Microsoft Forms. You can ask users on multiple types of questions, and you can even ask them to upload a file. While storing the answers to questions is quite straightforward, it’s not so with the attachments. Especially if the attachments are optional.
Users upload an attachment, and your flow works fine. But once there’s no attachment, the flow ends with an error. Why? What should the flow look like to handle both situations?
Why is it a problem?
Before you try to process the attachment(s), check the actual output from MS Forms. Send a response with an attachment to see it in the response body.
On the other side, response without an attachment has the “attachments question” empty.
And that’s the problem. If you follow many of the guides, you probably use the ‘Parse JSON’ action which causes the flow errors. It expects an input in the defined schema, and if there’s no input it fails – ‘Required property ‘content’ expects a value but got null. Path ”.’.
Just add a condition
The solution is very simple – just add a ‘Condition’. Check if the attachments dynamic content is not equal to “” (the value you can see on the screenshot with empty attachment). If it’s not equal to “”, save the attached file, otherwise do nothing.
When a Power Automate flow tells you that it received ‘null’ and fails, as when there’re no attachments in Forms, you can just add a ‘Condition’ to check the value before you try to use it. Check the output of the action when it’s empty, compare it with the correct empty value, and skip some actions if it’s true/false. There’s no need to think about complex solutions when all you need is a simple ‘Condition’.