Related Documents

Documents from a library related to the item, mapped by folder or metadata.

Widget description: relatedDocuments

The widget displays a table of documents from a document library that belong to the current item, allowing users to open, preview, and upload new files. Documents are associated with an item in two ways: by folder (each item has its own subfolder in the library) or by metadata (a library column stores the item's key). It is a virtual widget: files remain in the library and nothing is saved to the item. For general item attachments, use the Attachments field; for linking to another list, use Related Items.

Related Documents widget settings in the inspector: library, source key, mapping mode, and displayed columns

Adding to the form

  1. On the Widgets tab, select Related Documents (subtitle “Widget · document library”) and drag it into a section, or click “+”.
  2. In the inspector, select the Target document library. Only document libraries on the site are offered.
  3. Choose the File mapping mode and fill in its settings (see below).
  4. Select the displayed columns and configure preview sizes.

Until a library is selected, the widget displays “Widget is not configured” in the form.

Inspector settings

OptionPropertyDescriptionDefault
Target document librarylibraryId, libraryTitleLibrary containing the documents. Changing the library resets the foreign key column, displayed columns, and labels.not selected
Source key in this formsourceKeyField@itemId (ID of the current item) or internal name of a form field.@itemId
File mapping modemappingModefolder (Folder by item ID) or metadata (Metadata column). See Mapping modes.folder
Root subfolder (optional)folderPathTemplateFolder mode only: subfolder in the library under which item folders are stored, e.g., Projects.empty
Metadata foreign key column in libraryforeignKeyFieldMetadata mode only: library column that stores the item key.not selected
Displayed document columns in tableviewFieldsTable columns: standard name (File name), size (Size), modified (Modified date), editor (Modified by), and custom library columns. name is a link to the file with hover preview; size is formatted size. Native names FileLeafRef map to name and FileSizeDisplay / File_x0020_Size map to size. The Available columns block (with search) is used to check columns. In Displayed columns you set the order (drag-and-drop or arrows), custom label (columnLabels), and remove columns with the × button.["name", "size"]
Enable button to open item detail (DisplayForm)allowDisplayViewAdds a Properties button to each document to open its properties in a dialog.yes
Allow document upload (Drag & Drop)allowUploadShows a drop zone for dragging files and clicking to upload.yes
Allow deleting filesallowDeleteAdds a Delete button to every row. After confirmation the file is moved to the site recycle bin (not deleted permanently). The button is not shown in Display mode, for read-only fields or for a new item without an ID.no
Document preview dialog (on click): width, heightpreviewDialogWidth, previewDialogHeightSize of the preview dialog opened when clicking a file name. Value in px or %. Presets: default, 80 × 80%, 92 × 90%, 1200 × 800 px, 1400 × 900 px.1100 px × 88%
Enable quick preview on hoverenableHoverPreviewShows a quick preview when hovering over a file name.yes
Hover preview width and heighthoverPreviewWidth, hoverPreviewHeightSize of the quick preview in px or %. Presets: small 360 × 220, medium 480 × 320, large 640 × 420, 40 × 45%.360 × 220 px
Custom labelcustomLabelWidget title. If omitted, the library title is used, otherwise “Related Documents”.“Related Documents”
Width in section, Visible, Read-onlycolSpan, defaultVisible, defaultReadOnlyCommon options. Read-only hides upload.12, yes, no

Deleting files is off by default; turn it on with the allowDelete option. After confirmation the file is moved to the site recycle bin and the list refreshes. If the user has no permission to delete in the library, SharePoint rejects the action and the widget shows the error; see Limitations and tips.

Mapping modes

Folder by item ID (folder)

Item documents are stored in a folder named after the source key value: <library>/<subfolder>/<key>. For example, for an item with ID 42 and subfolder Projects, this is Projects/42. The widget creates the folder on first upload and overwrites any existing file with the same name. It only reads files directly inside that folder, not in subfolders; library columns of type Person and Lookup (including multi-value) are displayed as text. A non-existent folder is shown as an empty list.

This mode is the simplest and requires no extra column in the library. It does not use a filter, so it is not affected by the 5,000-item threshold.

Metadata column (metadata)

Documents can reside anywhere in the library and are linked to the item by the value of the foreign key column. On upload, the widget saves the file to the library root and populates the foreign key column: with the item ID for a lookup column, or with the key value for a text column. Foreign key column types (lookup, number, text) are handled the same way as in Related Items.

Metadata mode is subject to the unindexed column check. Without a selected foreign key column, metadata mode behaves like folder mode when reading documents, so always select a foreign key column.

Unindexed foreign key column (5,000-item threshold)

Metadata mode only. If the foreign key column is unindexed and the library has over 5,000 items, SharePoint would reject the query (List View Threshold). Therefore, the widget:

Details and recommendations are the same as in Related Items.

Metadata column mode: foreign key column picker and unindexed column warning with the Index column button

Runtime behavior

Widget in Edit mode: header with count, filter, drag-and-drop upload area, and document table with the Properties button

Resizing the quick preview: there is a handle in the bottom-right corner of the preview. Drag it to change the width (240 px to 92% of the window) and the content height (140 px to 75% of the window); the preview stays open while dragging. The handle also works from the keyboard (Tab): arrow keys resize by 20 px, Shift + arrow by 80 px. Double-clicking the handle restores the default size from the widget settings. The chosen size is remembered in the browser (shared by all documents). The Pin / enlarge button in the preview header opens the document in the large dialog.

Quick preview on hovering over a file name (thumbnail or embedded preview, size, date, author)
Document preview dialog opened after clicking a file name

Text translations

The title (customLabel) and column labels (columnLabels, keyed by name, size, modified, editor, or the custom column's internal name) can be translated. Without a custom label, standard columns switch automatically with the form language, while custom columns display their internal name. See Translations and Multilingual Forms.

Rules and scripts

Configuration example (JSON)

Folder mode:

{
  "internalName": "widget_related_docs",
  "customLabel": "Project documents",
  "fieldType": "relatedDocuments",
  "colSpan": 12,
  "defaultVisible": true,
  "relatedDocumentsConfig": {
    "libraryId": "00000000-0000-0000-0000-000000000000",
    "libraryTitle": "Project Documents",
    "mappingMode": "folder",
    "sourceKeyField": "@itemId",
    "folderPathTemplate": "Projects",
    "viewFields": ["name", "size", "modified", "editor"],
    "columnLabels": { "name": "File", "modified": "Modified", "editor": "Modified by" },
    "allowDisplayView": true,
    "allowUpload": true,
    "enableHoverPreview": true,
    "hoverPreviewWidth": "480px",
    "hoverPreviewHeight": "320px",
    "previewDialogWidth": "92%",
    "previewDialogHeight": "90%"
  }
}

Metadata mode (only changed properties):

{
  "relatedDocumentsConfig": {
    "libraryId": "00000000-0000-0000-0000-000000000000",
    "mappingMode": "metadata",
    "sourceKeyField": "@itemId",
    "foreignKeyField": "Projekt",
    "viewFields": ["name", "modified"]
  }
}

Limitations and tips