cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
GMorley
Regular Visitor

Attachment Field empty Parse JSON failed

Hi,

I've seen a few responses to how to update the Parse JSon code to get Flow to bypass it if the field is left blank, but I've not seen anything that explained explicitly where they update code goes.

 

In my case, I'm trying to bypass an attachment upload field. If anyone could help me bypass Parse JSON when the field "Attach Terms" is left blank I will be very grateful. 

 

the Schema is as follows:

{
    "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"
        ]
    }
}

 

Screenshot 2022-05-09 143440.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Super User
Super User

Hi, @GMorley , if I've understood you correctly, the code goes in the Schema. You essentially tell the Schema that it's OK to set a blank value, and not fail the input.

 

I'll dig it out, but I may have mentioned it on here at some point, too.

 

Ah, basically what @SPOLHE-C said ... except the array bracket goes teh other side of the field name.

 

So, I couldn't see AttachTerms in your schema, so I've used "id" as the field that might be without data, I would set that up in the schema like so:

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

 

 

View solution in original post

8 REPLIES 8
DamoBird365
Super User
Super User

Hi @GMorley 

 

You can use the filter array action (where the field is not empty) and then run your apply to each on this filtered array.

 

DamoBird365_0-1652119205261.png

 

As the filtered array does not contain your blank attachment key, it would not be in the array.

 

Damien

 

Hi, Thanks for responding,

 

Since it's the Parse that's failing, I assume I need to filter before the Parse, not before the Apply to each? The flow isn't getting as far as apply to each.

 

I'm assuming From should be the Form response ID, and name is the Attach Terms field?

 

I know I'm asking you to spell it out for me, but this is my first time exploring what flow can do. Thank you for your help.

 

 

@DamoBird365

 

I've had a go but I don't really understand what I'm trying to acheive with the filter.

 

I thought it was a case of checking the form response for attachements and if it does not contain blank then proceed with the Parse.

 

But if it doesn't do the Parse because the field was blank, it also wont proceed to send the emails. I want it to send the emails whether or not there is an attachment. I just don't want the flow to fail because a file wasn't attached.

 

I suppose i could put the emails parallel to the Parse JSON so that the attachments don't effect the emails but the flow will still fail at Parse JSON.

 

Screenshot 2022-05-10 095736 1.pngScreenshot 2022-05-10 095819 2.png

SPOLHE-C
Frequent Visitor

If you're happy with the flow otherwise, you can adjust the JSON directly to accept a null. In your code sample, where it says "type""string", change that to

"type": ["string","null"]

(do the same with "type": "integer" but NOT "type": "array"). 

 

...I'll look forward to a more elegant solution in the replies. (Edited to fix a typo.)

eliotcole
Super User
Super User

Hi, @GMorley , if I've understood you correctly, the code goes in the Schema. You essentially tell the Schema that it's OK to set a blank value, and not fail the input.

 

I'll dig it out, but I may have mentioned it on here at some point, too.

 

Ah, basically what @SPOLHE-C said ... except the array bracket goes teh other side of the field name.

 

So, I couldn't see AttachTerms in your schema, so I've used "id" as the field that might be without data, I would set that up in the schema like so:

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

 

 

Yes, that! (Can't even blame my system, entirely my error when typing.) Thanks for the quick fix.

eliotcole
Super User
Super User

Honestly no bigs! I hadn't realised you had also posted, so I just swerved around you a bit ;-). Frankly I was just thankful that you had, as it meant I could type it all up a bit quicker! 😅

 

Also, @GMorley , if you want the whole thing to carry on if the input is nil, then you can use a 'Run after' on the following flow action to ensure that it runs whether or not the JSON parser does its thing. Just make sure that your following actions are capable of dealing with a lack of information there. 😉

 

However, I think deeper interactions would require a bit more of your flow up here.

 

@eliotcole , @SPOLHE-C  thank you for this. I've updated the schema and the flow now works. 

 

Really appreciate the support. 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,039)