如何使用查阅字段链接 SharePoint 列表How to link SharePoint lists using lookup fields

本教程演示如何使用查阅字段连接两个 SharePoint 列表。This tutorial shows how you can connect two SharePoint lists with lookup fields.

概述Overview

SharePoint 提供两种查阅字段:SharePoint provides two types of lookup fields:

  • 查阅:链接到另一个列表:例如,Orders 列表可能有一个查阅字段,该字段链接到 Customer 列表中的客户;Lookup: links to another list: for example an Orders list may have a lookup field that links to customers in a Customer list;
  • 选项:单击或点击该字段会显示一个包含多个项的小菜单,你可以从中进行选择。Choice: clicking or tapping the field displays a small menu of items that you choose from.

在本教程中,将生成一个使用这些类型的查阅字段的应用。In this tutorial, you build an app that uses these kinds of lookup fields.

“查阅”字段用于哪些场合?What do you use lookup fields for?

企业中的数据不仅庞大,而且复杂。Data in an enterprise is large and complex. 一个 SharePoint 列表中的数据通常与另一个列表中的数据相关。Data in one SharePoint list often relates to data in another list. “查阅”字段是将此类业务数据汇集在一起的主要方式。Lookup fields are the primary way such business data comes together.

例如,你可能有一个包含“查阅”字段的 Orders 列表,该字段链接到 Customers 列表,以显示哪些客户已经下单。For example, you might have an Orders list which has a lookup field that links to a Customers list, to show which customer placed the order. 利用 Orders 列表中的“查阅”字段,还可以从 Customers 列表中获取其他数据。The lookup field in the Orders list lets you get other data from the Customers list as well. 还可以使用“查阅”字段将 Orders 列表连接到 Product 列表,引入所需的已订购产品相关信息,例如产品图片、规格、制造商详细信息等等。You might also use a lookup field to connect the Orders list to a Product list, and bring in information you need about the product ordered, such as product pictures, specifications, manufacturer details, etc.

“选项”字段用于哪些场合?What are Choice fields used for?

“选项”字段用于非常短的列表,使用此字段时,不会真的创建一个单独的列表,而是将列表值包含在一个小菜单中,当你单击或点击“选项”字段时会显示此菜单,你可以从此菜单中选择一个值。Choice fields are used for very short lists, but instead of actually creating a separate list, you include the list values in a small menu, which appears when you click or tap on the Choice field, and you select one of the values.

示例包括客户状态代码、产品供货状态、省/市/自治区代码等数据,以及基本上所有较短的固定列表。Examples include data like Customer Status Code, Product Availability, State Codes; basically any fixed list that is relatively short. 此类数据事实上可以作为单独的列表来实现,然后你可以使用“查阅”字段链接到它们,但一般来说,将其作为“选项”字段实现起来更加快捷。This data could in fact be implemented as separate lists, and then you would use a Lookup field to link to them, but it is usually easier and quicker to implement them as Choice fields.

在 SharePoint 中创建列表Create the lists in SharePoint

在本教程中,将 AssetsRepairShop 两个 SharePoint 自定义列表链接在一起。In this tutorial, you link two SharePoint custom lists together, Assets and RepairShop. Assets 列表用于跟踪团队的硬件设备。The Assets list is used to track hardware equipment in a team. 由于硬件经常损坏,因此我们使用 RepairShop 列表来跟踪可以修复硬件的本地商店。Since hardware gets broken from time to time, we use the RepairShop list to track the local shops which can fix it.

此示例中使用的查阅字段The lookup fields used in this example

RepairShop 列表使用 ContactEmail 字段来标识商店。The RepairShop list uses the ContactEmail field to identify the shop. 先定义此列表,以便 Assets 列表中的每一行都有可以指向的内容。This list is defined first so that each row in the Assets list has something to point to.

Assets 列表具有两个查阅字段:The Assets list has two lookup fields:

  • 一个字段名为“RepairShop”,类型为“查阅”,它使用电子邮件地址指向 RepairShop 列表中的条目;one called RepairShop, of type Lookup, which uses email addresses to point to entries in the RepairShop list;
  • 另一个字段名为“AssetType”,类型为“选项”,它列出此资产可能所属的硬件类型。one called AssetType, of type Choice, which lists the kinds of hardware that this asset might be.

你极有可能会根据需要跟踪的信息定义一些附加字段。You most likely would define additional fields, depending on the information you need to track.

定义 RepairShop 列表和添加数据Define the RepairShop list and add data

先执行此操作,以便在向 Assets 列表添加数据时,可从 Assets.RepairShop 查阅字段中选择 RepairShop 条目。You do this first, so that when you add data to the Assets list, RepairShop entries are available for you to choose from the Assets.RepairShop lookup field.

  1. 在 SharePoint 站点上,创建一个新的 RepairShop 列表。On your SharePoint site, create a new RepairShop list.

  2. 添加“单行文本”类型的 ContactEmail 字段。Add a ContactEmail field of type Single line of text.

  3. 添加所需的任何其他字段。Add any other fields you need.
  4. 单击或点击“+ 新建”向列表中输入示例数据,至少输入 3 行,每行包含不同的 ContactEmail 值。Click or tap + New to enter sample data into the list, at least 3 rows with different ContactEmail values. 当资产需要修复时,从中选择一个。When an asset needs to be repaired, you choose one of these.

定义 Assets 列表Define the Assets list

  1. 在 SharePoint 站点上,创建一个新的 Assets 列表。On your SharePoint site, create a new Assets list.
  2. 单击或点击加号,然后选择“更多”。Click or tap the plus sign and choose More.

  3. 添加一个“选项”类型的 AssetType 字段,然后在“分行键入每个选项”文本框中,填写要在选项菜单中显示的值。Add an AssetType field of type Choice, and in the Type each choice on a separate line text box, fill in the values you want to appear in the choice menu. 然后单击或点击“确定”。Then click or tap OK.
  4. 开始添加另一个字段,过程与步骤 2 一样:单击或点击加号,然后选择“更多”。Start to add another field, just like in step 2: click or tap the plus sign and choose More.
  5. 添加一个“查阅”类型的 RepairShop 字段,然后从“信息来源”文本框中选择“RepairShop”,从“在此列中”文本框中选择“ContactEmail”。Add a RepairShop field of type Lookup, choose RepairShop from the Get information from text box, and choose ContactEmail from the In this column text box. 然后单击或点击“确定”。Then click or tap OK.
  6. 添加所需的任何其他字段。Add any additional fields you want.

根据 Assets 列表创建应用Create an app from the Assets list

使用此应用向 Assets 列表添加数据。You use this app to add data to the Assets list.

  1. 打开 PowerApps Studio。Open PowerApps Studio. 如果未用过 PowerApps,请使用组织电子邮件地址免费注册,然后按照说明从 Windows 应用商店下载 PowerApps Studio。If you are new to PowerApps, sign up for free using your organizational email address and follow the instructions to download PowerApps Studio from the Windows store.
  2. 在“文件”菜单中(沿左边缘),单击或点击“新建”,然后单击或点击“SharePoint”。In the File menu (along the left edge), click or tap New, and then click or tap SharePoint.

  1. 从“最近访问过的站点”列表中选择 SharePoint 站点,或直接在文本框中输入站点 URL。Choose your SharePoint site from the Recent sites list or enter your site's url directly into the text box. 单击或点击“转到”。Click or tap GO.

  1. 从 SharePoint 站点中选择主列表,此例中为 AssetsChoose the main list from your SharePoint site, in this example, Assets. 单击或点击右下角的“连接”按钮。Click or tap the Connect button in the lower-right corner.

向 Assets 列表添加数据Add data to the Assets list

现在可以运行应用,查看查阅字段的“查看详细信息”屏幕的外观。Now you can run the app and see how the view details screen looks for the lookup fields.

  1. 按 F5,或选择“预览”( )。Press F5 or select Preview ( ).
  2. 单击或点击右上角的 + 符号以添加条目。Click or tap the + symbol in the upper right corner to add an entry.
  3. 为此资产输入“标题”。Enter a Title for this asset.
  4. 单击或点击 AssetType 向下箭头。Click or tap the AssetType dropdown arrow. 显示的值是创建此字段时输入的值。The values displayed are those you entered when you created this field. 选择其中一个条目。Choose one of the entries.

  5. 单击或点击 RepairShop 向下箭头。Click or tap the RepairShop dropdown arrow. 选择其中一个条目。Choose one of the entries.

  6. 在右上角单击或点击复选标记以保存新条目。In the upper-right corner, click or tap the check mark to save the new entry.
  7. (可选)重复此过程,以便向列表中添加所需数量的项。(optional) Repeat this procedure to add as many items to the list as you want.
  8. 按 Esc 返回默认工作区。Press Esc to return to the default workspace.

有关For more information