Skip to main content

Notifications

Power Automate - Building Flows
Answered

MS Form Submitted without attachments

Posted on by 6
Hi,
 
I have a flow that stores responses from an MS Form in a SharePoint List.

The first question in the Form allows the responder to attach files. I currently use a Parse JSON step (found online) which enables me to add attachments to the List item in a For Each loop that references outputs('Parse_JSON')['body'].
 
The flow fails at the Parse JSON stage when no attachments are included.

Is there a practical work around for this?

Parse JSON step code below for reference.
 
Thanks for reading
Matt
{
  "type": "ParseJson",
  "inputs": {
    "content": "@body('Get_response_details')?['r52970a37d7f44534842ce10180188f96']",
    "schema": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "link": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "type": {},
          "size": {
            "type": "integer"
          },
          "referenceId": {
            "type": "string"
          },
          "driveId": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "uploadSessionUrl": {}
        },
        "required": [
          "name",
          "link",
          "id",
          "type",
          "size",
          "referenceId",
          "driveId",
          "status",
          "uploadSessionUrl"
        ]
      }
    }
  },
  "runAfter": {
    "Condition": [
      "SUCCEEDED"
    ]
  }
}
 
  • Verified answer
    Mark Nanneman Profile Picture
    Mark Nanneman 329 on at
    MS Form Submitted without attachments
    If you don't need the items that have no attachments, you could filter them out, or use a condition to check the '{HasAttachments}' property.

    Another option is you could add the "null" type to the list of accepted types for your properties in your ParseJSON schema.   

    Whenever you use the "ParseJSON" and you generate the schema from sample data, it will fail if it ever gets a null value for a property (that wasn't null in the sample data).  A work around is to find the "type": setting for any properties that might be null, and change the value to an array that includes the original type and "null".
     
    "name": {
                "type": "string"
              }
    
    //will fail if "name" is ever missing or null
    
    
    "name": {
                "type": ["string","null"]
              }
    //will work if "name" is ever missing or null.
    Generally though I find that "ParseJSON" is more trouble than it's worth in most cases.  It's best to just get a sample JSON body and keep it open in NotePad or something in another window for reference.  Then you can use expressions to refernce whatever property you want from your data output.  Usining a "?" will cause it to accept nulls if the property is missing from the data on the current run.

    outputs('Compose_Object_to_Parse')?['propertyYouWant']
  • Suggested answer
    David_MA Profile Picture
    David_MA 7,541 on at
    MS Form Submitted without attachments
    To check if there are attachments with an attachment question in MS Forms, add a condition and use a length expression to calculate the number of attachments:
     
    The expression is length(outputs('Get_response_details')?['body/your-attachment-question'])
     
    If it returns greater than 0, on the yes side of the condition do whatever you are doing. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard