SP へありますオブジェクト (sp.js)

Specifies a relationship to a lookup field.

**適用対象:**apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.RelatedField()

Members

The RelatedField object has the following members.

Constructor

The RelatedField object has the following constructor.

Constructor

Description

RelatedField

Initializes a new instance of the SP.RelatedField object.

Properties

The RelatedField object has the following properties.

Property

Description

fieldId

Gets a value that specifies a GUID that identifies the related lookup field.

listId

Gets a value that specifies a GUID that identifies the list containing the related lookup field.

lookupList

Gets a value that specifies the list that the related lookup field looks up to.

relationshipDeleteBehavior

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.

webId

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>

REST resource endpoint

Endpoint URI structure

http://<sitecollection>/<site>/_api/web/lists(listid)/GetRelatedFields()/GetByFieldId(fieldid)

HTTP requests

This resource supports the following HTTP commands:

POST syntax

POST http://<sitecollection>/<site>/_api/web/lists(listid)/GetRelatedFields()/GetByFieldId(fieldid)