cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jchen1
Frequent Visitor

Retrieve user profiles from a collection of user emails

I have a collection called userEmails that I have populated with every employee's company email address. I am trying to use the Office365Users connection to pull the User Profiles into a new collection called userProfiles. 

 

Currently my code is :

 

ClearCollect(
    userProfiles,
    ForAll(
        userEmails.Value,
        Office365Users.UserProfileV2(First(userEmails).Value)
    )
);

 

 I have tried UserProfile and UserProfileV2 and both ways just populate blank rows in my collection userProfiles. 

 

userEmails has 6 test email addresses in it and when I run the code, userProfiles populates to 6 rows with the correct headers for UserProfile but no data. Does anyone know the issue or a different solution to my task?

1 ACCEPTED SOLUTION

Accepted Solutions
v-yutliu-msft
Community Support
Community Support

Hi @jchen1 ,

Do you want to save user profile in a collection?

Could you show me your collection of userEmails?

Have you checked your emails in userEmails in your talent?

I've made a similar test and found that you need to make a little change on your original formula.

Here's my test for your reference:

1)create  userEmails collection:

ClearCollect(userEmails,["Phoebel@Wic....ft.com","Test5@W...rosoft.com"])

4107.PNG

 2)create  userProfiles collection:

ClearCollect(
    userProfiles,
    ForAll(
        userEmails.Value,
        Office365Users.UserProfileV2(Value)
    )
)

First(userEmails).Value only represents the first email in useremail collection. You just need to use fieldname Value in Office365Users.UserProfileV2 function.

ForAll(collection,Office365Users.UserProfileV2(fieldname)) represents you will perform Office365Users.UserProfileV2(fieldname) one by one record.

 

Then I will get a collection with user profiles.

4108.PNG

 

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Max44
Helper V
Helper V

Will it be safe to assume that the users email address is stored in the AD? In that case you might use DirectorySearcher to query for a user.

 

 

 
eka24
Super User III
Super User III

Have you read this post:
https://powerusers.microsoft.com/t5/Building-Power-Apps/Build-a-collection-of-user-profiles-from-O36...

 

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

v-yutliu-msft
Community Support
Community Support

Hi @jchen1 ,

Do you want to save user profile in a collection?

Could you show me your collection of userEmails?

Have you checked your emails in userEmails in your talent?

I've made a similar test and found that you need to make a little change on your original formula.

Here's my test for your reference:

1)create  userEmails collection:

ClearCollect(userEmails,["Phoebel@Wic....ft.com","Test5@W...rosoft.com"])

4107.PNG

 2)create  userProfiles collection:

ClearCollect(
    userProfiles,
    ForAll(
        userEmails.Value,
        Office365Users.UserProfileV2(Value)
    )
)

First(userEmails).Value only represents the first email in useremail collection. You just need to use fieldname Value in Office365Users.UserProfileV2 function.

ForAll(collection,Office365Users.UserProfileV2(fieldname)) represents you will perform Office365Users.UserProfileV2(fieldname) one by one record.

 

Then I will get a collection with user profiles.

4108.PNG

 

 

Best regards,

 

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

jchen1
Frequent Visitor

@v-yutliu-msft 

Thank you! This worked great! 

 

My userEmails was a collection with a blank column (Result) and a column (Value) that looked just like the example you made. After changing my code to match what you had, userProfiles populated with every employee profile.

paulewert
Frequent Visitor

Watch out. Being that UserProfileV2 takes a "User (UPN)" parameter described as "user principal name or email id" and User().Email may not return a value which matches that returned by UserProfileV2. This is particularly true for users with multiple registered SMTP values (these can be seen using Outlook client's Address Book search and then viewing the "E-mail Addresses" tab of the contact card). Thus, this action may not work as expected if you pass in the user's email address. In our environment, the user's username portion of their email address does not always match their user principal name. (Mine does not.) Without experimentation or better documentation, it's hard to know if UserProfileV2 is taking an email address or a user principal name + domain. I side-stepped the ambiguity and simply used the user's ID as returned from Microsoft365Users.MyProfileV2({'$select':"id"}).id.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (37,403)