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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

ForAll Collection

(0) ShareShare
ReportReport
Posted on by 249

Hello! I need a little help FENGYANG_1-1682513979124.png

Please see screenshot below;

Why the ForAll Collection make the same data. In fact the displayname of Attachments are different.

How should I correct the code.

Thank you.

FENGYANG_2-1682514288865.png

 

Clear(attachlist);
ForAll(
 Gallery3.AllItems,
 Collect(
 attachlist,
 {
 Name: Last(
 LookUp(
 Gallery3.AllItems,
 ID = ID
 ).Attachments
 ).DisplayName
 }
 )
);

 

 

 

 

 

Categories:
I have the same question (0)
  • AhmedSalih Profile Picture
    6,680 Moderator on at

    Hello, @LaurensM , Crossed each other. 🙂

    If my reply helped you, please give a 👍  , & if it solved your issue, please give a 👍  & Accept it as the Solution to help other community members find it more.

    I am primarily available on weekdays from 6-10 PM CT and 5-10 PM CT on weekends.

    Visit my Blog: www.powerplatformplace.com

    Visit my YouTube Channel: https://www.youtube.com/@powerplatformplace/videos

     

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @FENGYANG,

     

    Since you are using the Gallery as a datasource, you don't need to provide it with another lookup to the same source. Please try:

    Clear(attachlist);
    ForAll(
     Gallery3.AllItems,
     Collect(
     attachlist,
     {
     Name: Last(ThisRecord.Attachments).DisplayName
     }
     )
    );

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • FENGYANG Profile Picture
    249 on at

    @LaurensM  Hi, thank you for hlep, There seems to be a mistake.

    FENGYANG_0-1682515128904.png

     

     

  • LaurensM Profile Picture
    12,516 Moderator on at

    You currently have a trailing dot after the Last() function, you will need to write .DisplayName as in your previous code. Does the error persist after adding this - if so, what particular error are you receiving?

  • FENGYANG Profile Picture
    249 on at

    Please see screenshot below

     "Last(ThisRecord.Attachments).DisplayName" is error

     

    FENGYANG_0-1682515673749.png

     

  • FENGYANG Profile Picture
    249 on at

    The type is incompatible. The 'Name' column in the data source you are updating should be of type 'Text', but you are using type 'Error'.The function 'Collect' has some invalid arguments.The specified column cannot be accessed in this context.The function 'Last' has some invalid arguments.Name: Last(ThisRecord.Attachments).DisplayName);

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    @FENGYANG ah indeed, the attachment column does not seem to be accessible in this context. I tried a few variations but always ended up with that exact error.

     

    What you could do is add a label to your gallery with the following text property (and set the visible property to false):

    Last(ThisItem.Attachments).DisplayName

     

    Let's name this label 'lblAttachment', your collect code would be the following:

    Clear(attachlist);
    ForAll(
     Gallery3.AllItems,
     Collect(
     attachlist,
     {
     Name: ThisRecord.lblAttachment.Text
     }
     )
    );

     

    I hope this helps!

  • Verified answer
    FENGYANG Profile Picture
    249 on at

    @LaurensM  Thank you very much, this is so clever.

  • FENGYANG Profile Picture
    249 on at

    Hi @LaurensM 

    if an item has multiple attachments, I hope collect the the displayname of attachments in Gallery.

    I have tyied some ways, but these did not work,

    FENGYANG_1-1682562702653.png

    FENGYANG_2-1682562830888.png

     

     

     

     

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @FENGYANG,

     

    Since we are using Last() we will only fetch the last attachment. Should you want to see all attachment names, separated by an enter / line break you can change the label text property to:

    Concat(ThisItem.Attachments,DisplayName,Char(10))

     

    I hope this helps!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 610

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard