如何使用查閱欄位連結 SharePoint 清單How to link SharePoint lists using lookup fields

本教學課程示範如何透過查閱欄位連接兩個 SharePoint 清單。This tutorial shows how you can connect two SharePoint lists with lookup fields.


SharePoint 提供兩種類型的查閱欄位︰SharePoint provides two types of lookup fields:

  • 查閱︰連結至其他清單:例如,訂單清單可能會有查閱欄位是連結到客戶清單中的客戶;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.

例如,您的訂單清單中可能會有連結至客戶清單的查閱欄位,以用於顯示訂購該筆訂單的客戶。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. 訂單清單中的查閱欄位也可讓您取得客戶清單的資料。The lookup field in the Orders list lets you get other data from the Customers list as well. 您也可以使用查閱欄位將訂單清單連結至產品清單,以取得有關訂購產品的資訊,例如:產品圖片、規格、製造商詳細資料等等。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

在本教學課程中,您將連結兩個 SharePoint 自訂清單、資產維修商店In this tutorial, you link two SharePoint custom lists together, Assets and RepairShop. 資產清單用於追蹤小組中的硬體設備。The Assets list is used to track hardware equipment in a team. 由於硬體會不時故障,因此我們使用維修商店清單追蹤可提供維修服務的當地商店。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

維修商店清單使用連絡電子郵件欄位來識別商店。The RepairShop list uses the ContactEmail field to identify the shop. 應先定義這份清單,資產清單中的每個資料列才有指向目標。This list is defined first so that each row in the Assets list has something to point to.

資產清單有兩個查閱欄位︰The Assets list has two lookup fields:

  • 其中一個是維修商店 (屬於查閱類型),其使用電子郵件地址指向維修商店清單中的項目;one called RepairShop, of type Lookup, which uses email addresses to point to entries in the RepairShop list;
  • 另一個是資料類型 (屬於選擇類型),其列出此資產可能是哪一種硬體。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.

定義維修商店清單並新增資料Define the RepairShop list and add data

您先執行此步驟,日後新增資料到資產清單時,即可從 Assets.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 網站上建立新的維修商店清單。On your SharePoint site, create a new RepairShop list.

  2. 新增屬於單行文字類型的連絡電子郵件欄位。Add a ContactEmail field of type Single line of text.

  3. 新增您需要的任何其他欄位。Add any other fields you need.

  4. 按一下或點選 [+ 新增],在清單中輸入範例資料,至少 3 列並應具有不同的連絡電子郵件值。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.

定義資產清單Define the Assets list

  1. 在 SharePoint 網站上建立新的資產清單。On your SharePoint site, create a new Assets list.

  2. 按一下或點選加號,然後選擇 [更多]Click or tap the plus sign and choose More.

  3. 新增選擇類型的資產類型欄位,在 [一行鍵入一個選擇] 文字方塊中,填入要在選擇功能表中顯示的值。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. 新增查閱類型的維修商店欄位,從 [資訊取得來源] 文字方塊選擇 [維修商店],然後從 [在此欄位中] 文字方塊,選擇 [連絡電子郵件]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.

從資產清單建立應用程式Create an app from the Assets list

您可以使用此應用程式將資料加入至資產清單。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.

  3. [最近使用的網站] 清單中選擇 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.

  4. 從 SharePoint 網站選擇主要清單,此範例選擇的是資產清單。Choose the main list from your SharePoint site, in this example, Assets. 按一下或點選右下角的 [連接] 按鈕。Click or tap the Connect button in the lower-right corner.

將資料加入至資產清單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. 按一下或點選 [資產類型] 下拉箭號。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. 按一下或點選 [維修商店] 下拉箭號。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