cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Null in Parse JSON when Upload in Forms is Optional

I have a flow that is triggered when a user submits a response to a Microsoft Form.  A user has the option to upload an attachment to the form and then the flow writes their responses to a Sharepoint List.  The flow works if a user does upload a file but fails when a user does not upload a file.  Before the flow creates the Sharepoint items, I am using a Parse JSON to get that information - how do I change the schema so that it accepts a null file?

 

{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": [
"string",
"null"
]
},
"link": {
"type": [
"string",
"null"
]
},
"id": {
"type": [
"string",
"null"
]
},
"type": {},
"size": {
"type": [
"integer",
"null"
]
},
"referenceId": {
"type": [
"string",
"null"
]
},
"driveId": {
"type": [
"string",
"null"
]
},
"status": {
"type": [
"integer",
"null"
]
},
"uploadSessionUrl": {}
},
"required": [
"name",
"link",
"id",
"type",
"size",
"referenceId",
"driveId",
"status",
"uploadSessionUrl"
]
}
}
1 ACCEPTED SOLUTION

Accepted Solutions

@bsmith736464 

Whoops!  I just re-read the original post.  So, you're new schema is fine probably so go ahead and leave it.  What we want to do is add a condition to check if the output of forms responses, specifically the file upload, is empty, ya?

 

So, I added this:

20190111a.PNG

 

And the function looks like this:

empty(body('Get_response_details')?['r4ef3850bbdab45d536205d433a669706'])
 
Which is just what happens when you type Empty(      and then click into the dynamic values to grab the field for the upload...  you're long string of gibberish will be different than mine.
 
If there's nothing there, then it will return a 'true' so you can build your flow to go down the appropriate path.
 
Sorry for missing that in your original post.  Let us know how this works out.
-Ed-
 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

 

 

View solution in original post

23 REPLIES 23
edgonzales
Most Valuable Professional
Most Valuable Professional

@bsmith736464 

Hi there!  You'll want to remove the parts that have "Type" and "String" in it.  That will open things up a bit so Power Automate accepts whatever the previous step hands it.  

 

Check out John Liu's Thesis on Parse JSON for more details.  Hope that helps.

 

Keep us posted.

-Ed-

 

 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

Thank you so much for your help @edgonzales 

 

Unfortunately I am still getting the error "Unable to process template language expressions in action 'Parse_JSON' inputs at line '1' and column '2770': 'Required property 'content' expects a value but got null. Path ''.'." when I run the flow after I cleaned up the schema to be:

 

{
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
},
"link": {
},
"id": {
},
"type": {},
"size": {
},
"referenceId": {
},
"driveId": {
},
"status": {
},
"uploadSessionUrl": {}
},
"required": [
"name",
"link",
"id",
"type",
"size",
"referenceId",
"driveId",
"status",
"uploadSessionUrl"
]
}
}
 
Any other suggestions?

@bsmith736464 

Whoops!  I just re-read the original post.  So, you're new schema is fine probably so go ahead and leave it.  What we want to do is add a condition to check if the output of forms responses, specifically the file upload, is empty, ya?

 

So, I added this:

20190111a.PNG

 

And the function looks like this:

empty(body('Get_response_details')?['r4ef3850bbdab45d536205d433a669706'])
 
Which is just what happens when you type Empty(      and then click into the dynamic values to grab the field for the upload...  you're long string of gibberish will be different than mine.
 
If there's nothing there, then it will return a 'true' so you can build your flow to go down the appropriate path.
 
Sorry for missing that in your original post.  Let us know how this works out.
-Ed-
 

If you liked this reply, please give it a thumbs up! If this reply has answered your question or resolved your challenge, please consider marking it as a Solution. This helps other users find it more easily via search.

 

 

usayd
Regular Visitor

The condition works fine if you only have one Upload attachment question in your form. In my case, I have a form with two or three multiple attachment questions that are option and the flow starts there with approvals, pdfs, etc. So repeating all these process for each condition might not be the best solution these cases.

I've tried using the expression below in a Compose but didn't succeed.

if(empty(body('Get_response_details')?['r4f4f31cbf708413db8dc102623628a95']),null,body('Get_response_details')?['r4f4f31cbf708413db8dc102623628a95']['name'])

Someone has tried some other expression?
Thank you.

Hi Usayd, I may be over simplifying your case here, so I'm sorry if I am, but you don't have to replicate each additional flow step in your conditions. 

 

You can put in a condition to check if the file question is empty and then resume the rest of your flow. (All of this is happening inside an Apply to Each, so it also works when nested.) For example, here I check if the file question was left blank and then leave the "yes" box empty. If the question is blank, the flow just skips the steps where I needed the file to be uploaded and moves on to the next steps in my configuration. It doesn't end there. 

 

stephanie2_0-1610129260054.png

 

Later in the Flow I reference the data parsed here (the Body input in the Apply to Each 2) and I put the same exact condition in there with the same empty() expression that checks if that particular question on the form was left blank. Then same thing, I leave the "yes" box empty so the flow continues and I don't have to duplicate the proceeding options in each of the condition boxes. 

stephanie2_1-1610129442426.png

 

Your flow may have many more dependencies than mine, but it took me a while when building this to realize I could apply the condition to only that single step and have the rest of the Flow resumed as normal instead of replicating all of the ending steps each time I had a condition.

 

Hope this helps!

 

 

 

Anonymous
Not applicable

Hi!

 

Am I doing it right? I have 4 attachments and all of them are optional.

 

bishimori_0-1611220332066.png

I created these steps to all parse JSON

 

Hi Bishimori, 

 

From what I'm able to see in your screenshot, this looks correct! 

Hello their can you please tell me the process of doing this i also have 3 attachments but i am finding it difficult to decode what you have done.

Please help me

You have no idea how long I've been searching for this exact answer. It should have been this simple from the beginning. THANK YOU.

Hello,
I think I have the same problem, I have a form with a possibility to attach files, if a file is attached, the flow works, if no file is attached it doesn't work, I've tried it now as here in the solution, get but then an error.


 

InvalidTemplate. Unable to process template language expressions for action 'Bedingung_10' at line '0' and column '0': 'The template function 'emptyoutputs' is not defined or not valid.'.

Unable to process template language expressions for action 'Bedingung_10' at line '0' and column '0': 'The template function 'emptyoutputs' is not defined or not valid.'.

 

 

I implemented it as shown in the picture, what am I doing wrong?

 

ThomasH_0-1657109580808.png

 

 

emptyoutputs('Antwortdetails_abrufen_2')?['body/r9845a7aaa5474396a935017c1dfb4371']

 

 

Thank you

Hi Thomas, Try moving the parse JSON step to the "If No" side of the condition. Right now your flow says, if there's no file, parse the file. You want it so say, if it's not true that there's no file, parse the file. 

I'm having the same issue and I added your condition of Empty is True and the problem I have is I have an Apply to Each that then throws an error, what do I need to do that so that if there is an attachment is sends the email? 

 

c20916_0-1665165513774.png

 

Hi There, you need to put each step that will use the file inside a condition. I believe this error is telling you there's no data for that step when there's no file. See this part of my original post, 

 

'Later in the Flow I reference the data parsed here (the Body input in the Apply to Each 2) and I put the same exact condition in there with the same empty() expression that checks if that particular question on the form was left blank. Then same thing, I leave the "yes" box empty so the flow continues and I don't have to duplicate the proceeding options in each of the condition boxes. "

 

Let me know if that helps!

I'm new to this so some of this is hard to understand, but I basically have two separate flows, one that works whether there is an attachment or not but it will send an email without an attachment,  Then I have a separate flow that will work if there is an attachment and send the email with the attachment, but if there is no attachment, then the flow fails.  However if there is an attachment, then I get two emails, one with and one without an attachment. 

 

I can't figure out a way to combine the flows so that I just have one.  I ended up taking out the apply to each in this flow so this is the one that always works, but if there is an attachment, it won't attach it to the email.  So if I want this to work I guess the question is where would I put what you are referencing in this flow so that it sends an attachment?

 

c20916_0-1666034982430.png

 

Hi, the email step needs to use the file if one is uploaded, so you need to put it inside of a condition that checks if the file was uploaded using the same empty expression as in the first condition of your flow.  In the "if yes," (no file) box, put an email step with no attachment. In the "if no" box, put an email step where the file gets attached. So you'll have two corresponding email steps (which will match excluding the attachment), but the flow will only ever use one of them at a time.

 

Every step that needs the file needs to be in a condition. If this is your whole flow and the end is the email, then you could just create two branches and avoid having multiple conditions. The multiple-condition method is best used to skip duplicating items when you have a very complex flow. 

This is my complete Flow.  There is one step at the top that I couldn't get in the screen, but it was just when a new response is submitted.  This flow runs successfully whether or not I attach something , however if I have an attachment when it sends the email it does not attach the file.  So I'm stuck as to how to make it so it sends the email with an attachment if there is one, and still sends an email if there isn't an attachment. 

 

c20916_0-1666042623509.png

And this is how I have the condition setup.  What would I need to add to have it send the email with the attachment if it's there? 

 

c20916_1-1666042705802.png

 

I'm facing the same the issue. I have 5 fields to upload attachments.

The flow works if a user does upload a file in all the fields but fails when a user does not upload a file in a field.

Below is my flows, can you please help to change it correctly?

kinghnvn_0-1669360221290.png

kinghnvn_1-1669360230622.png

 

hmenzel
Frequent Visitor

I have a similar issue, so I'm hoping I can dust off this thread. 

Adding the Empty condition still breaks the flow, and the error is related to parse Json. "The execution of template action 'Apply_to_each_3' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')' is of type 'Null'. The result must be a valid array."  Any ideas?

Capture3.PNG

 

 

Hey There, can we see what's in your Apply to Each 3?

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (811)