SP.RelatedField object
Specifies a relationship to a lookup field.
Last modified: March 09, 2015
Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013
var object = new SP.RelatedField()
The RelatedField object has the following members.
Constructor
The RelatedField object has the following constructor.
|
Constructor |
Description |
|---|---|
|
Initializes a new instance of the SP.RelatedField object. |
Properties
The RelatedField object has the following properties.
|
Property |
Description |
|---|---|
|
Gets a value that specifies a GUID that identifies the related lookup field. |
|
|
Gets a value that specifies a GUID that identifies the list containing the related lookup field. |
|
|
Gets a value that specifies the list that the related lookup field looks up to. |
|
|
Gets a value that specifies the action taken by the system for items in the list specified by listId when an item in the current list is deleted. |
|
|
Gets a value that specifies the GUID that identifies the site containing the list with the related lookup field. |
The following example creates an input button on an application page that displays the Id of fields related to the Tasks list of the current site.
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"> <script type="text/ecmascript" language="ecmascript"> var relatedFieldCollection = null; function runCode() { var clientContext = new SP.ClientContext.get_current(); if (clientContext != undefined && clientContext != null) { this.web = clientContext.get_web(); var listCollection = web.get_lists(); var item = listCollection.getByTitle("Tasks"); // Get a collection of lookup fields that use this list as a data source // and that have FieldLookup.IsRelationship set to true. this.relatedFieldCollection = item.getRelatedFields(); clientContext.load(this.relatedFieldCollection); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } } function onQuerySucceeded(sender, args) { var fieldInfo = ''; var fieldEnumerator = this.relatedFieldCollection.getEnumerator(); while (fieldEnumerator.moveNext()) { var relatedField = fieldEnumerator.get_current(); // Get the GUID that identifies the related lookup field. fieldInfo += 'Related Field ID: ' + relatedField.get_fieldId().toString() + '\n'; } alert(fieldInfo); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script> <input id="Button1" type="button" value="Run Code" onclick="runCode()" /> </asp:Content>