从 PowerApps 连接到 Office 365 用户连接Connect to Office 365 Users connection from PowerApps

Office 365 用户

借助 Office 365 用户,可以使用 Office 365 帐户访问组织中的用户配置文件。Office 365 Users lets you access user profiles in your organization using your Office 365 account. 你可以执行各种操作,如获取配置文件、用户的经理或者直接上级。You can perform various actions such as get your profile, a user's profile, a user's manager or direct reports.

可以在应用上的标签中显示此信息。You can display this information in a label on your app. 可以显示一个函数、多个函数,甚至组合不同的函数。You can display one function, multiple functions, or even combine different functions. 例如,可以创建一个组合了用户名和电话号码的表达式,然后在应用中显示此信息。For example, you can create an expression that combines the User Name and Phone Number, and then display this information in your app.

本主题演示了如何将 Office 365 用户添加为连接、如何将 Office 365 用户添加为应用的数据源,以及如何在库控件中使用表数据。This topic shows you how to add Office 365 Users as a connection, add Office 365 Users as a data source to your app, and use table data in a gallery control.

 

What you need to get started

添加连接Add a connection

  1. 添加数据连接并选择 Office 365 用户Add a data connection and select Office 365 Users:

    连接到 Office 365

  2. 选择“连接”,如果系统提示你登录,请输入你的工作帐户。Select Connect, and if prompted to sign in, enter your work account.

Office 365 用户连接已创建并已添加到你的应用。The Office 365 Users connection has been created and added to your app. 现在可供使用。Now, it's ready to be used.

在应用中使用连接Use the connection in your app

显示有关当前用户的信息Show information about the current user

  1. 在“插入”菜单上,选择“标签”On the Insert menu, select Label
  2. 在函数栏中,将其 Text 属性设置为下列公式之一:In the function bar, set its Text property to any of the following formulas:

    Office365Users.MyProfile().Department
    Office365Users.MyProfile().DisplayName
    Office365Users.MyProfile().GivenName
    Office365Users.MyProfile().Id
    Office365Users.MyProfile().JobTitle
    Office365Users.MyProfile().Mail
    Office365Users.MyProfile().MailNickname
    Office365Users.MyProfile().Surname
    Office365Users.MyProfile().TelephoneNumber
    Office365Users.MyProfile().UserPrincipalName
    Office365Users.MyProfile().AccountEnabled

此时,标签显示所输入的有关当前用户的信息。The label shows the information that you entered about the current user.

显示其他用户的信息Show information about another user

  1. 在“插入”菜单上,选择“文本”,然后选择“文本输入”。On the Insert menu, select Text, and then select Text input. 将其重命名为 InfoAboutRename it InfoAbout:

    重命名控件

  2. InfoAbout 中,键入或粘贴组织中某个用户的电子邮件地址。In InfoAbout, type or paste an email address of a user in your organization. 例如,键入 yourName@yourCompany.comFor example, type in yourName@yourCompany.com.
  3. 添加一个“标签”控件(使用“插入”菜单),然后将“Text”属性设置为以下公式之一:Add a Label (Insert menu), and set its Text property to any of the following formulas:

    • 显示其他用户的信息:To show information about another user:

      Office365Users.UserProfile(InfoAbout.Text).Department
      Office365Users.UserProfile(InfoAbout.Text).DisplayName
      Office365Users.UserProfile(InfoAbout.Text).GivenName
      Office365Users.UserProfile(InfoAbout.Text).Id
      Office365Users.UserProfile(InfoAbout.Text).JobTitle
      Office365Users.UserProfile(InfoAbout.Text).Mail
      Office365Users.UserProfile(InfoAbout.Text).MailNickname
      Office365Users.UserProfile(InfoAbout.Text).Surname
      Office365Users.UserProfile(InfoAbout.Text).TelephoneNumber
      Office365Users.UserProfile(InfoAbout.Text).UserPrincipalName
      Office365Users.UserProfile(InfoAbout.Text).AccountEnabled

    • 显示其他用户经理的相关信息:To show information about another user's manager:

      Office365Users.Manager(InfoAbout.Text).Department
      Office365Users.Manager(InfoAbout.Text).DisplayName
      Office365Users.Manager(InfoAbout.Text).GivenName
      Office365Users.Manager(InfoAbout.Text).Id
      Office365Users.Manager(InfoAbout.Text).JobTitle
      Office365Users.Manager(InfoAbout.Text).Mail
      Office365Users.Manager(InfoAbout.Text).MailNickname
      Office365Users.Manager(InfoAbout.Text).Surname
      Office365Users.Manager(InfoAbout.Text).TelephoneNumber
      Office365Users.Manager(InfoAbout.Text).UserPrincipalName
      Office365Users.Manager(InfoAbout.Text).AccountEnabled

此时,标签显示所输入的有关指定用户或其经理的信息。The label shows the information that you entered about the user you specified or that user's manager.

注意:如果正在基于 Common Data Service 中的某个实体开发应用,则可以基于 ID 而非电子邮件地址指定用户。Note: If you're developing an app based on an entity in the Common Data Service, you can specify a user based on ID instead of email address.

例如,可以自动创建应用,添加包含“标签”控件的屏幕,然后将控件的“Text”属性设置为以下公式:For example, you can create an app automatically, add a screen that contains a Label control, and set the control's Text property to this formula:
Office365Users.UserProfile(BrowseGallery1.Selected.CreatedByUser).DisplayNameOffice365Users.UserProfile(BrowseGallery1.Selected.CreatedByUser).DisplayName

如果创建联系人,并在应用的浏览屏幕中选择此联系人,那么“标签”控件会显示你的显示名称。If you create a contact and select that contact in the browse screen of the app, the Label control will show your display name.

显示其他用户的直接上级Show the direct reports of another user

  1. 添加“文本输入”控件(“插入”菜单 >“文本”),并将其重命名为 InfoAboutAdd a Text input control (Insert menu > Text), and rename it InfoAbout.
  2. InfoAbout 中,输入组织中用户的电子邮件地址。In InfoAbout, enter the email address of a user in your organization. 例如,输入 yourManagersName@yourCompany.comFor example, enter yourManagersName@yourCompany.com
  3. 添加带有文本库(“插入”菜单 >“”),并将其 Items 属性设置为下列公式:Add a With text gallery (Insert menu > Gallery), and set its Items property to the following formula:

    Office365Users.DirectReports(InfoAbout.Text)

    库将显示有关所输入用户的直接上级的信息。The gallery shows information about the direct reports of the user you entered.

    选择库后,右侧窗格显示该库的选项。With the gallery selected, the right-hand pane shows options for that gallery.

  4. 在第二个列表中,选择 JobTitleIn the second list, select JobTitle. 在第三个列表中,选择 DisplayNameIn the third list, select DisplayName. 库将更新,以显示这些值。The gallery is updated to show these values.


    注意:第一个框实际上是图像控件。NOTE The first box is actually an image control. 如果没有图像,可以删除图像控件,然后在原处添加一个标签控件。If you don't have an image, you can delete the image control, and add a label in its place. 添加和配置控件是一个好资源。Add and configure controls is a good resource.

搜索用户Search for users

  1. 添加“文本输入” 控件(“插入”菜单 >“文本”),并将其重命名为 SearchTermAdd a Text input control (Insert menu > Text), and rename it SearchTerm. 输入要搜索的名称。Enter a name to search. 例如,输入你的名。For example, enter your first name.
  2. 添加带有文本库(“插入”菜单 >“”),并将其 Items 属性设置为下列公式:Add a With text gallery (Insert menu > Gallery), and set its Items property to the following formula:

    Office365Users.SearchUser({searchTerm: SearchTerm.Text})

    库显示名称中包含所输入的搜索文本的用户。The gallery shows users whose name contains the search text you entered.

    选择库后,右侧窗格显示该库的选项。With the gallery selected, the right-hand pane shows options for that gallery.

  3. 在第二个列表中,选择 MailIn the second list, select Mail. 在第三个列表中,选择 DisplayNameIn the third list, select DisplayName.

    此时,库中的第二个和第三个标签会进行更新。The second and third labels in the gallery are updated.

查看可用函数View the available functions

此连接包括以下函数:This connection includes the following functions:

函数名称Function Name 说明Description
MyProfileMyProfile 检索当前用户的配置文件Retrieves the profile for the current user
UserProfileUserProfile 检索特定用户配置文件Retrieves a specific user profile
ManagerManager 检索指定用户经理的用户配置文件Retrieves user profile for the manager of the specified user
DirectReportsDirectReports 返回指定用户的直接上级Returns the direct reports for the specified user
SearchUserSearchUser 检索用户配置文件的搜索结果Retrieves search results of user profiles

MyProfileMyProfile

获取我的配置文件:检索当前用户的配置文件。Get my profile: Retrieves the profile for the current user.

输入属性Input properties

无。None.

输出属性Output properties

属性名称Property Name 类型Type 说明Description
DepartmentDepartment 字符串string 用户的部门。Department of the user.
DisplayNameDisplayName 字符串string 用户的显示名称。Display name of user.
GivenNameGivenName 字符串string 用户的名字。Given name of user.
IDId 字符串string 用户 IDUser id
JobTitleJobTitle 字符串string 用户的职务。Job Title of the user.
邮件Mail 字符串string 用户的电子邮件 ID。Email id of user.
MailNicknameMailNickname 字符串string 用户的昵称。Nickname of user.
SurnameSurname 字符串string 用户的姓氏。Surname of user.
TelephoneNumberTelephoneNumber 字符串string 用户的电话号码。Telephone number of user.
UserPrincipalNameUserPrincipalName 字符串string 用户的主体名。User Principal Name.
AccountEnabledAccountEnabled 布尔值boolean 帐户启用标志。Account enabled flag.

UserProfileUserProfile

获取用户配置文件:检索特定用户配置文件。Get user profile: Retrieves a specific user profile.

输入属性Input properties

名称Name 数据类型Data Type 需要Required 说明Description
IDId 字符串string yes 用户主体名或电子邮件 IDUser principal name or email id

输出属性Output properties

属性名称Property Name 类型Type 说明Description
DepartmentDepartment 字符串string 用户的部门。Department of the user.
DisplayNameDisplayName 字符串string 用户的显示名称。Display name of user.
GivenNameGivenName 字符串string 用户的名字。Given name of user.
IDId 字符串string 用户 IDUser id
JobTitleJobTitle 字符串string 用户的职务。Job Title of the user.
邮件Mail 字符串string 用户的电子邮件 ID。Email id of user.
MailNicknameMailNickname 字符串string 用户的昵称。Nickname of user.
SurnameSurname 字符串string 用户的姓氏。Surname of user.
TelephoneNumberTelephoneNumber 字符串string 用户的电话号码。Telephone number of user.
UserPrincipalNameUserPrincipalName 字符串string 用户的主体名。User Principal Name.
AccountEnabledAccountEnabled 布尔值boolean 帐户启用标志。Account enabled flag.

ManagerManager

获取经理:检索指定用户经理的用户配置文件Get manager: Retrieves user profile for the manager of the specified user

输入属性Input properties

名称Name 数据类型Data Type 需要Required 说明Description
IDId 字符串string yes 用户主体名或电子邮件 IDUser principal name or email id

输出属性Output properties

属性名称Property Name 类型Type 说明Description
DepartmentDepartment 字符串string 用户的部门。Department of the user.
DisplayNameDisplayName 字符串string 用户的显示名称。Display name of user.
GivenNameGivenName 字符串string 用户的名字。Given name of user.
IDId 字符串string 用户 IDUser id
JobTitleJobTitle 字符串string 用户的职务。Job Title of the user.
邮件Mail 字符串string 用户的电子邮件 ID。Email id of user.
MailNicknameMailNickname 字符串string 用户的昵称。Nickname of user.
SurnameSurname 字符串string 用户的姓氏。Surname of user.
TelephoneNumberTelephoneNumber 字符串string 用户的电话号码。Telephone number of user.
UserPrincipalNameUserPrincipalName 字符串string 用户的主体名。User Principal Name.
AccountEnabledAccountEnabled 布尔值boolean 帐户启用标志。Account enabled flag.

DirectReportsDirectReports

获取直接上级:获取直接上级Get direct reports: Get direct reports

输入属性Input properties

名称Name 数据类型Data Type 需要Required 说明Description
IDId 字符串string yes 用户主体名或电子邮件 IDUser principal name or email id

输出属性Output properties

属性名称Property Name 类型Type 说明Description
DepartmentDepartment 字符串string 用户的部门。Department of the user.
DisplayNameDisplayName 字符串string 用户的显示名称。Display name of user.
GivenNameGivenName 字符串string 用户的名字。Given name of user.
IDId 字符串string 用户 IDUser id
JobTitleJobTitle 字符串string 用户的职务。Job Title of the user.
邮件Mail 字符串string 用户的电子邮件 ID。Email id of user.
MailNicknameMailNickname 字符串string 用户的昵称。Nickname of user.
SurnameSurname 字符串string 用户的姓氏。Surname of user.
TelephoneNumberTelephoneNumber 字符串string 用户的电话号码。Telephone number of user.
UserPrincipalNameUserPrincipalName 字符串string 用户的主体名。User Principal Name.
AccountEnabledAccountEnabled 布尔值boolean 帐户启用标志。Account enabled flag.

SearchUserSearchUser

搜索用户:检索用户配置文件的搜索结果Search for users: Retrieves search results of user profiles

输入属性Input properties

名称Name 数据类型Data Type 需要Required 说明Description
searchTermsearchTerm 字符串string no 搜索字符串。Search string. 适用于:显示名称、名字、姓氏、邮件、邮件昵称和用户主体名Applies to: display name, given name, surname, mail, mail nickname, and user principal name

输出属性Output properties

属性名称Property Name 类型Type 说明Description
DepartmentDepartment 字符串string 用户的部门。Department of the user.
DisplayNameDisplayName 字符串string 用户的显示名称。Display name of user.
GivenNameGivenName 字符串string 用户的名字。Given name of user.
IDId 字符串string 用户 IDUser id
JobTitleJobTitle 字符串string 用户的职务。Job Title of the user.
邮件Mail 字符串string 用户的电子邮件 ID。Email id of user.
MailNicknameMailNickname 字符串string 用户的昵称。Nickname of user.
SurnameSurname 字符串string 用户的姓氏。Surname of user.
TelephoneNumberTelephoneNumber 字符串string 用户的电话号码。Telephone number of user.
UserPrincipalNameUserPrincipalName 字符串string 用户的主体名。User Principal Name.
AccountEnabledAccountEnabled 布尔值boolean 帐户启用标志。Account enabled flag.