“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.
Summary
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’.
Amazing help! Was racking my brain this morning trying to figure it out.
Thanks
Help Please? I have tried to handle the same error when there’s no attachment, but I’m attempting to send an email to a group with / without the uploaded file(s). In the “Yes” side of the condition, when attempting to Initialize the attachment Variable (which I understand to be required in order to handle multiple attachments and send all of them in one email), i get an error saying “The operation ‘Initialize variable’ can only be used at top level.”
How do i get around this if I can’t initialize the variable? I also tried adding the condition at the end after initializing the variable, but before sending A) an email with attachments or B) an email without attachments, but it still fails the Parse JSON step since there’s no attachment.
You really need to initialize all the variables on the top level. “Initialize” doesn’t mean you need to set the contents of the variable. It means the system has some named space reserved for your data. Just put the Initialize variable in the beginning of the flow, give the name and type.
Later in the flow you use Set variable action to accomplish what you need.
Perfect thank you!!
Note that it is not the “smart quotes”, but 2 of the Quotation Mark characters that you would get if you used Notepad to type them into. Developers will not want to copy/paste the “” into their field, for example, but just type 2 marks normally, and it will automatically put 2 of the correct marks into it.
I had tried checking the attachment question field from the MS Form as a null, in the expression. This did not work. But checking for 2 quotation marks with nothing between them? Works like a gem. Thanks!
Well this blog post is the closest thing I’ve found to my problem. I have exactly this problem with an instant flow triggered in a PowerApp.
Although the ‘file’ parameter is defined as optional, not including it in the method call fails.
A post explaining this would be awesome.
If there is a file in the attachments control, the code below works, the flow runs and does a number of things ending with creation of an item (with attachment) in an SP list. If there is nothing in the attachments control, this fails.
If(
IsMatch(
BusinessKCDataCardValue.Text,
“(?:http(s):\/\/)[\w.-]+(?:\.[\w.-]+)+[\w\-\.,@?^=%&:/~\+#\{\}]*”
) Or IsBlank(BusinessKCDataCardValue.Text),
PeerFeedbackFlow.Run(
EmployeeDataCardValue.Selected.Email,
FeedbackDataCardValue.Selected.Value,
DecriptionDataCardValue.Text,
If(
IsBlank(BusinessKCDataCardValue.Text),
“N/A”,
(BusinessKCDataCardValue.Text)
),
If(
IsBlank(OrderNumberValue.Text),
“N/A”,
(OrderNumberValue.Text)
),
// Last(AttachmentsDataCardValue17.Attachments).Name,
{
file: {
name: Last(AttachmentsDataCardValue17.Attachments).Name,
contentBytes: Last(AttachmentsDataCardValue17.Attachments).Value
}
}
);
Navigate(Screen2),
Notify(
“Invalid URL!”,
NotificationType.Error
)
);
big thx, had exactly this solution but slightly wrong syntax. Saved my day.