SP.Field object

Represents a field in a list on a Microsoft SharePoint Foundation Web site.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.Field()

Members

The Field object has the following members.

Constructor

The Field object has the following constructor.

Constructor

Description

Field

Initializes a new instance of the SP.Field object.

Methods

The Field object has the following methods.

Method

Description

deleteObject

Deletes the field from the list, from the site, or from the content types within the list.

setShowInDisplayForm

Sets the value of the ShowInDisplayForm property for this field.

setShowInEditForm

Sets the value of the ShowInEditForm property for this field.

setShowInNewForm

Sets the value of the ShowInNewForm property for this field.

update

Commits changed properties of the field.

updateAndPushChanges

Commits changed properties of the field and optionally propagates changes to all lists that use the field.

validateSetValue

Validates and parses the input value and updates the value of the list item.

Properties

The Field object has the following properties.

Property

Description

canBeDeleted

Gets a value that specifies whether the field can be deleted.

defaultValue

Gets or sets a value that specifies the default value for the field.

description

Gets or sets a value that specifies the description of the field.

direction

Gets or sets a value that specifies the reading order of the field.

enforceUniqueValues

Gets or sets a value that specifies whether to require unique field values in a list or library column.

entityPropertyName

Gets the name of the entity property for the list item entity that uses this field.

fieldTypeKind

Gets or sets a value that specifies the type of the field.

filterable

Gets a value that specifies whether list items in the list can be filtered by the field value.

fromBaseType

Gets a Boolean value that indicates whether the field derives from a base field type.

group

Gets or sets a value that specifies the field group.

hidden

Gets or sets a value that specifies whether the field is hidden in list views and list forms.

id

Gets a value that specifies the field identifier.

indexed

Gets or sets a Boolean value that specifies whether the field is indexed.

internalName

Gets a value that specifies the field internal name.

jsLink

Gets or sets the name of an external JS file containing any client rendering logic for fields of this type.

Note

The JSLink property is not supported on Survey or Events lists. A SharePoint calendar is an Events list.

readOnlyField

Gets or sets a value that specifies whether the value of the field is read-only.

required

Gets or sets a value that specifies whether the field requires a value.

schemaXml

Gets or sets a value that specifies the XML schema that defines the field.

schemaXmlWithResourceTokens

Gets the schema that defines the field and includes resource tokens.

scope

Gets a value that specifies the server-relative URL of the list or the site to which the field belongs.

sealed

Gets a value that specifies whether properties on the field cannot be changed and whether the field cannot be deleted.

sortable

Gets a value that specifies whether list items in the list can be sorted by the field value.

staticName

Gets or sets a value that specifies a customizable identifier of the field.

title

Gets or sets value that specifies the display name of the field.

typeAsString

Gets or sets a value that specifies the type of the field.

typeDisplayName

Gets a value that specifies the display name for the type of the field.

typeShortDescription

Gets a value that specifies the description for the type of the field.

validationFormula

Gets or sets a value that specifies the data validation criteria for the value of the field.

validationMessage

Gets or sets a value that specifies the error message returned when data validation fails for the field.

Example

The following example creates an input button on an application page that gets a specified field, creates a description for the field, and displays the field title and new description.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    var fieldCollection;
    var oneField = null;
    function runCode() {
        var clientContext = SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            var webSite = clientContext.get_web();
            taskList = webSite.get_lists().getByTitle("Tasks");

            fieldCollection = taskList.get_fields();
            this.oneField = fieldCollection.getByInternalNameOrTitle("Title");

            this.oneField.set_description("MyNewFieldDescription");
            this.oneField.update();

            clientContext.load(this.fieldCollection);
            clientContext.load(this.oneField);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
        }
    }

    function OnLoadSuccess(sender, args) {
        var fieldInfo = '';
        fieldInfo += 'Field Title: ' + oneField.get_title() + '\n' + 'Description: ' + oneField.get_description() + '\n';
        alert(fieldInfo);
    }

    function OnLoadFailed(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

See Field resource for more information.

Endpoint URI structure

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

HTTP requests

This resource supports the following HTTP commands:

DELETE syntax

DELETE http://<sitecollection>/<site>/_api/web/lists(listid)/fields(fieldid)

MERGE syntax

MERGE http://<sitecollection>/<site>/_api/web/lists(listid)/fields(fieldid)

POST syntax

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

PUT syntax

PUT http://<sitecollection>/<site>/_api/web/lists(listid)/fields(fieldid)