web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Null Value in Apply to...
Power Automate
Unanswered

Null Value in Apply to Each Control when updating SharePoint list with Microsoft Forms output

(0) ShareShare
ReportReport
Posted on by 59

Hello - I have a Microsoft Form to retrieve data from technicians in the field and save it to a SharePoint list. To save the responses to the SharePoint list, I am using the "Record form responses in SharePoint template".

The form has branching logic, and photos are required for one branch. To save the photos to the list as well as the responses, I am using the "Apply to each" control. In the form, there is a second question to include additional photos. The second item is not required and is applicable to all branches.

When I execute a form path where photos aren't required, I believe the value in the control is null which causes a problem. I have issues when photos are not uploaded in the required field (because photos are only required for one of the paths). Geez! A lot of explanation, sorry.

Here is the overview of the flow, and I provided the details of the area where I'm getting stuck (failure message). Any help is appreciated. Thanks!

Error message: The execution of template action 'Apply_to_each_attachment' failed: the result of the evaluation of 'foreach' expression '@json(outputs('Get_response_details')?['body/r63a3dee2e10048d2afc5fc9e83944418'])' is of type 'Null'. The result must be a valid array.

Flow Overview:

Flow Overview.png

Detail for Apply to Each control:

Flow 1.png

Error:

Flow failed.PNG

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    The easiest fix is to probably add a Coalesce() function around the array argument in the apply to each.  That way if attachments is null you can substitute an empty array so the loop just bypasses instead of erroring out.  Something like this

    coalesce(triggerOutputs()?['body/attachments'],variables('varArray'))

    Where varArray is an array variable that was initialized as an empty array.

  • ConnieMaldonado Profile Picture
    59 on at

    I'm trying to implement your suggestion, and thanks so much for it!  I'm new to flows, so I'm not sure where to put the coalesce statement.  Do I put it in the json statement.  Can I have multiple lines in the statement, and how do I initialize varArray as an empty array? Thanks!!

     

    Flow Question.PNG

  • Verified answer
    Pstork1 Profile Picture
    68,697 Most Valuable Professional on at

    That's the right place to put it, but why are you using a JSON() function?  The attachments outputs are already JSON and so is the empty array created by Create array.  I also don't see the Coalesce() function I specified.  You don't need the JSON(), but you do need the Coalesce().

     

    To initialize the empty array, just use an Initialize Variable action set for an array, but don't supply any values.

  • ConnieMaldonado Profile Picture
    59 on at

    Aha!  I got it finally.  Your input was invaluable.  I didn't realize that to initialize an array as empty, simply leave the value blank.  Duh.  My first one, so ... thanks again! 😀

    Initialize Variable.PNG

  • Rebekah278 Profile Picture
    30 on at

    Hello,

    I am in a similar situation.  I have added the Coalesce to my expression but now I am getting this error:

    "Unable to process template language expressions for action 'Apply_to_each_attachment' at line '0' and column '0': 'The template language function 'triggeroutputs' must not have any parameters.'."

    This is my expression:  
    coalesce(triggeroutputs('Get_response_details')?['body/r8e7db9481b264488abadd0387c75ce9c'],variables('varArray'))
    If someone could help me with this, it would be much appreciated!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard