SP.FieldCollection Class

Applies to: SharePoint Foundation 2010

Represents a collection of SP.Field Class objects.

SP.FieldCollection

Inherits

SP.ClientObjectCollection Class

Example

The following example creates an input button on an application page that uses the FieldCollection collection to display the available fields in the Announcements list.

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

    var fieldCollection;

    function runCode() {
        var clientContext = new SP.ClientContext();
        var targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
        fieldCollection = targetList.get_fields();
        clientContext.load(fieldCollection, 'Include(Title)');
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }

    function onQuerySucceeded() {
        var message = "The following fields are available in the Announcements list:\n\n";
        var fields = '';
        var listEnumerator = fieldCollection.getEnumerator();
        while (listEnumerator.moveNext()) {
            fields += listEnumerator.get_current().get_title() + "; ";
        }
        alert(message + fields);
    }

    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>

See Also

Reference

SP.FieldCollection Methods

SP.FieldCollection Properties

SP Namespace