Linked schemas are useful for providing filtered views on schemas in another container and they provide a way to apply security settings at a finer granularity than at the level of whole folders. (See Related Topics below for other methods.) Linked schemas are especially useful when you want to reveal some data in a folder without granting access to the whole folder. For example, suppose you have the following data in a single folder A. Some data is private, some is public, and some is intended for specific audiences:
URLs are also removed from the source tables. The insert, update, delete URLs are removed because the linked schema is considered read-only. The details URL and URLs on columns are removed because the URL would rarely work in the linked schema container. If desired, the lookups and URLs can be added back in the linked schema metadata xml. To carry over the attachment field links in the source table, first copy the metadata that enables the link in the source table and paste it into the analogous field in the linked table. See below for an example.
To create a linked schema in folder B that reveals data from folder A:
You can add metadata xml that filters the data or modifies how it is displayed on the page.
In the following example, a filter is applied to the table Location -- a record is shown only when InUse is true.
<tables xmlns="http://labkey.org/data/xml" xmlns:cv="http://labkey.org/data/xml/queryCustomView">
<filters name="public-filter">
<cv:filter column="InUse" operator="eq" value="true"/>
</filters>
<table tableName="Location" tableDbType="NOT_IN_DB">
<filters ref="public-filter"/>
</table>
</tables>
Attachment fields in the source table are not automatically carried over into the target schema, but you can activate attachment fields by providing a metadata override. For example, the XML below activates attachment field the in the list called "SourceList", which is in the Project/Folder called "SourceFolder". The activated field is called "AttachedDoc". To get the URL pattern, go to the source List and hover over one of the links in the attachment column. Right-click and copy the link.
<tables xmlns="http://labkey.org/data/xml">
<table tableName="SourceList" tableDbType="NOT_IN_DB">
<columns>
<column columnName="AttachedDoc">
<url>/labkey/list/SourceFolder/download.view?listId=1&entityId=${EntityId}&name=${AttachedDoc}</url>
</column>
</columns>
</table>
</tables>
For more information about metadata xml, see Query Metadata.
Default values can be saved as a "schema template" -- by overriding parts of the template, you can change:
<LABKEY_HOME>/externalModules/myModuleA/schemas/ClientA.template.xml
The example .template.xml file below provides a default linked schema and a default filter xml for Client A:
ClientA.template.xml
<templateSchema xmlns="http://labkey.org/data/xml/externalSchema"
xmlns:dat="http://labkey.org/data/xml"
xmlns:cv="http://labkey.org/data/xml/queryCustomView"
sourceSchemaName="assay.General.Custom Assay">
<tables>
<tableName>Data</tableName>
</tables>
<metadata>
<dat:tables>
<dat:filters name="client-filter">
<cv:filter column="Client" operator="eq" value="A Client"/>
</dat:filters>
<dat:table tableName="Data" tableDbType="NOT_IN_DB">
<dat:filters ref="client-filter"/>
</dat:table>
</dat:tables>
</metadata>
</templateSchema>
You can override any of the default values, even after selecting the template:
For example, you can create a schema for Client B by (1) creating a new linked schema based on the template for Client A and (2) overriding the metadata xml, as shown below: