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 loop error

(0) ShareShare
ReportReport
Posted on by 314

List code below is not able to run, any idea how to fix it?  Thanks!

 

ClearCollect( colInfoEmailList, { Name: "", Mail: "", UPN: "", Type: "" } );

// Loop through the EmailArray and check each email address
ForAll(
Split("UserA@gmail.com;UserB@gmail.com", ";"),
// Get the user profile information using the Office365Users connector
Set(UserProfile, Office365Users.UserProfileV2(Result));
// Check if the user profile is blank or not
If(
// If not blank, add the user profile information and the type column to the Collection
!IsBlank(colInfoEmailList),
Collect(
colInfoEmailList,
{
DisplayName: UserProfile.displayName,
Mail: UserProfile.mail,
UserPrincipalName: UserProfile.userPrincipalName,
Type: "User"
}
)
)
);

Categories:
  • WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @usaman45 ,

    WHat exactly are you trying to do here ?

    ForAll(
     Split(
     "UserA@gmail.com;UserB@gmail.com", 
     ";"
     ),
     Set(
     UserProfile, 
     Office365Users.UserProfileV2(Result)
     );

    you cannot set a Variable inside ForAll() - also the output of Split is Value, not Result (it was changed some time ago).

    If you want the first non-blank profile, you could do this

    Set(
     UserProfile, 
     Coalesce(
     Office365Users.UserProfileV2(UserA@gmail.com),
     Office365Users.UserProfileV2(UserB@gmail.com)
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • usaman45 Profile Picture
    314 on at

    My goal is to loop through a string that has multiple email addresses and check if they are active or not. If an email address is active, I want to add it to a UserCollection with the following attributes: DisplayName: UserProfile.displayName, Mail: UserProfile.mail, UserPrincipalName: UserProfile.userPrincipalName, Type: “User”

    Is there a better way to do this?

  • Verified answer
    WarrenBelz Profile Picture
    156,940 Most Valuable Professional on at

    Hi @usaman45 ,

    Something like this should do it

    ForAll(
     Split(
     "UserA@gmail.com;UserB@gmail.com", 
     ";"
     ),
     With(
     {_Profile: Office365Users.UserProfileV2(Value)},
     If(
     !IsBlank(_Profile.mail),
     Collect(
     colInfoEmailList,
     {
     DisplayName: _Profile.displayName,
     Mail: _Profile.mail,
     UserPrincipalName: _Profile.userPrincipalName,
     Type: "User"
     }
     )
     )
     )
    );

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard