Microsoft Flow + Cognito Forms: Error uploading Form attachments to SharePoint Online

This post is decidedly more product-specific, but hopefully it will help someone out there facing the same issue that is looking for an easy fix.

Cognito Forms is an online form building service that, while I personally haven't tried, has been in use by some departments at this organization. They also provide Microsoft Flow integration to their forms, which is ultimately how this post came to be.

The Problem:

The Flow is simple enough, it takes a submitted Cognito Form, does a handful of things, and ultimately populates a SharePoint List with the form information and attaches the form attachments to the list entry. This works exactly as expected for most forms submitted - assuming the files don't exceed a certain combination of size and quantity (which I didn't have time to nail down specifically during troubleshooting).

Under most circumstances, the following Flow action would work just fine:





cf_eufatso_one

The Cognito Forms-provided Name and Content attributes work as expected and all is right in the world.

However, when the planets align just so, you get this instead:





cf_eufatso_two

So what's going on? The error does a pretty good job of pointing us in the right direction...

The Solution:

What the error is basically telling us is the Content attribute of the Cognito Forms attachment is empty.

We can verify this by checking the output of the Flow Trigger ('Cognito Forms: When a new entry is updated') to see what a working example looks like versus a failed run.

Here's what we get:

WorkingNot Working




cf_eufatso_three




cf_eufatso_four
As you can see, Content is nowhere to be found in the output - but it still shows up as an option in our 'Add Attachments' action. So how do we get the file content then?

Thankfully, the Cognito Forms trigger does provide us with an attribute called 'File'. This is a direct link to the attachment (that expires after a certain length of time) which we can use to retrieve the file content ourselves! How do we do that?

With an HTTP GET action!

Simply place an 'HTTP' action before the 'Add Attachments' action like so:





cf_eufatso_five
Set Method to 'GET' and Uri to the 'File' attribute provided by the trigger.

The Output ('Body') of this action will be the attachment - which is returned as an Object (which, after a lot of banging my head on the desk trying to convert this to something else, is actually exactly what we want!).





cf_eufatso_six

Go ahead and throw that 'Body' into the File Content of the 'Add Attachments' action like so:





cf_eufatso_seven

And catch your breath as you finally get the little green checkmark to let you know all is right in the world again.






cf_eufatso_eight

Comments

Popular posts from this blog

PowerApps: Apply Multiple Filters to a Gallery

Microsoft Flow: Identify Soon-to-Be-Deprecated Office 365 Connectors in Your Environments Using Powershell