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 Platform Community / Forums / Power Apps / Lookup Office 365 info...
Power Apps
Answered

Lookup Office 365 information on selected user

(0) ShareShare
ReportReport
Posted on by 16

Hi,

 

I have a canvas app with a

  • Text Input (TextInput2)
  • ComboBox (ComboBox1)
    • Items Property = Office365Users.SearchUser({searchTerm:TextInput2.Text})

In the above, I search the name in TextInput2 and then select the user from ComboBox1.

 

I want to add a Label field where by I can display the selected user's Department. IE:

 

  • ComboBox1 value = Adele Vance
  • Label1 value = Marketing

I don't want to use a gallery

 

In Label 1's Text property, I have tried: Office365Users.UserProfileV2(ComboBox1.Selected.DisplayName).department however I get the following error:

 

Office365Users.UserProfileV2 failed: {"error": { "code": "ResourceNotFound", "message", "User not found", "innerError": { "date": "2023-01-02T12:54:12", "request-id": "3361e318-9171-4c8d-80f2-15db9cdfdd14". "client-request-id": "3361e318-9171-4c8d-80f2-15db9cdfdd14"}}}

 

Can anyone help?

 

TIA

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @stanswell84,

     

    With Office365Users.SearchUser({searchTerm:TextInput2.Text}) being the value of the Items property in the ComboBox, the selected item will be a record (includes department info). This means that you could actually just reference the Combobox1.Selected.Department instead of using Office365Users.UserProfileV2(...).

     

    During my test case setting the label Text property to the code below, worked:

    ComboBox1.Selected.Department

    In this case we only expect Combobox1 to have 1 selected record. 

     

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

    Thanks!

  • MatthRichardsUK Profile Picture
    2 on at

    It looks like the error you are getting is due to the UserProfileV2 function not being able to find the user specified in the ComboBox1.Selected.DisplayName property.

    One thing you can try is to use the UserProfileV2 function inside the UpdateContext function, to set a context variable to the selected user's department. Here's an example of how you could do this:

    1. Add a new context variable called selectedUserDepartment, and set its default value to an empty string: UpdateContext({selectedUserDepartment: ""})
    2. In the OnChange event of the ComboBox1 control, use the UserProfileV2 function to set the selectedUserDepartment context variable to the selected user's department:

    UpdateContext({
    selectedUserDepartment: Office365Users.UserProfileV2(ComboBox1.Selected.DisplayName).department
    })
    3. Set the property of the Label1 control to the value of the selectedUserDepartment context variable: Label1.Text = selectedUserDepartment
    This should allow you to display the selected user's department in the Label1 control. Let me know if you have any questions or if you need further assistance.

  • v-liwei-msft Profile Picture
    Microsoft Employee on at

    Hi @stanswell84 

     

    Office365Users.UserProfileV2 needs to fill in the parameter as the user principal name or Id.
    You can modify the formula to:

    Office365Users.UserProfileV2(ComboBox1.Selected.Id).department 

    Or

    Office365Users.UserProfileV2(ComboBox1.Selected.UserPrincipalName).department

     

    Best Regards,

    Levi

  • stanswell84 Profile Picture
    16 on at

    Thanks very much! It was so simple in the end!!

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 846

#2
Valantis Profile Picture

Valantis 532

#3
Haque Profile Picture

Haque 410

Last 30 days Overall leaderboard