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 Apps
Unanswered

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:
I have the same question (0)
  • WarrenBelz Profile Picture
    152,867 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
    152,867 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

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 759 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 310 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 228

Last 30 days Overall leaderboard