# ForeignKey

## **Specs**

<table><thead><tr><th width="320">Label</th><th>Value</th></tr></thead><tbody><tr><td><strong>Version</strong></td><td>2.2.0 (updated on 2025-03-19)</td></tr><tr><td><strong>Developer</strong></td><td>Labii Inc.</td></tr><tr><td><strong>Type</strong></td><td>Column</td></tr><tr><td><strong>Support Configuration</strong></td><td>Yes</td></tr><tr><td><strong>Support Readonly view</strong></td><td>Yes</td></tr><tr><td><strong>Support Edit view</strong></td><td>Yes</td></tr><tr><td><strong>Support Form view</strong></td><td>Yes</td></tr><tr><td><strong>Support Default value</strong></td><td>Yes</td></tr><tr><td><strong>Support Import</strong></td><td>Yes</td></tr><tr><td><strong>Allow multiple</strong></td><td>Yes</td></tr></tbody></table>

## Overview

The ForeignKey widget in Labii establishes a link to another record, enabling a direct association between related data sets. This widget facilitates the creation of a connection to a single additional record, offering a seamless and clickable link to access the linked data. Through this functionality, users can establish clear relationships between different sets of information, fostering efficient navigation and exploration within the Labii platform.

## Use case

1. Use this widget to define the storage of samples.
2. Use this widget to define the account of contacts.

## Configuration

The widget will function without additional setup. However, the configuration options empower you to impose additional restrictions on the tables to which the linked data can be associated. Leave it empty to include all tables.

* **Tables** - Select one or more tables to link. To allow records from all tables, leave it empty.
* **Query** - Further queries to narrow the results. To exclude archived records, use is\_archived=false.

### Examples:

```json
{
    "query":"is_archived=false&cell__column__sid=FILO0a40x560b4HMRW27bg&cell__data__icontains={{jmps0a40x560dclqvAFKPU:data.sid}}",
    "tables":[{"sid":"9beh0a40x12507afkpuzEJ","name":"contacts"}]
}
```

## Views

See the interface of the widget in the following views.

### **Readonly view**

Readonly view display the values of the column.

<figure><img src="https://files.gitbook.com/v0/b/gitbook-legacy-files/o/assets%2F-LHVg57XIRcjV-Vbubtn%2F-LX7X5eHkQb38Ant1Yw2%2F-LX7YRMplaia6WAcAQJv%2Fforeignkey-labii-eln-lims.png?alt=media&#x26;token=b3c6571f-de44-44f3-8a9b-e8d50a76bf74" alt=""><figcaption></figcaption></figure>

* **Update Name**: Use this function to correct the display name of a foreign record when the name is different.

### **Edit view**

The Edit view is the interface that allows you to modify the value.

<figure><img src="https://files.gitbook.com/v0/b/gitbook-legacy-files/o/assets%2F-LHVg57XIRcjV-Vbubtn%2F-LX7X5eHkQb38Ant1Yw2%2F-LX7YWpNYJHIRTiBf-Er%2Fforeignkey-edit-labii-eln-lims.png?alt=media&#x26;token=d6fd6a1b-8283-4421-a689-f99a8c09adbd" alt=""><figcaption></figcaption></figure>

The widget allows users to add a new record if it does not already exist. To add a new record, click the “Add XXX” button. This will open a form to collect the necessary information for the record. Once the record is added, the page will redirect back to the original view.

### **Form view**

The Form view is the field integrated into the add form for collecting values when creating a new record.

The Form view is same as the Edit view.

## Data

Each widget in Labii stores data in a unique manner; refer below to understand how data from this widget is stored.

### Data format

JSON object with the keys of `sid` and `name`.

```json
{"sid": "", "name": ""}
```

### **Default value**

The Default Value field within the column allows you to specify the default value when a record is created.

Default value shall be the name or uid of a record.

### **Import value**

The Import Value is the value you need to include in your Excel table for it to be imported into Labii.

Import value shall be the name or uid of a record.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.labii.com/widgets/column-widgets/form/dropdown/foreignkey.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
