Click here to Skip to main content
12,550,397 members (44,411 online)
Click here to Skip to main content
Add your own
alternative version



Add Fields to SharePoint 2013 List Using JSOM (ECMAScript Client Object Model)

, 13 Mar 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
How to add fields to an existing list.

In my previous post I described how to add a list to SharePoint. In here I'm going to  describe how to add fields to an existing list. First you need to refer same JavaScript files in your script page (SP.core.js,SP.runtime.js,SP.js).

There are a few approaches that you can use to add fields to the existing list. But in my personal opinion I like the following approach because

  • It is easy rather that use XML to add entire field  
  • Intelligence are support based on field type (text, choice, user ..)
  • Code is more readable than xml
<script type="text/ecmascript">
    function addFields() {
        var clientContext = new SP.ClientContext.get_current();
        var oWebsite = clientContext.get_web();
        //Geting reference to the list
        oList = clientContext.get_web().get_lists().getByTitle('CustomList');
        // Get filed collection
        var fldCollection = oList.get_fields();

        var f1 = clientContext.castTo(
                        fldCollection.addFieldAsXml('<Field Type="Text" DisplayName="NewField" Name="NewField" />', true, SP.AddFieldOptions.addToDefaultContentType),
        f1.set_description("sample desc");
        var f2 = clientContext.castTo(
                    oList.get_fields().addFieldAsXml('<Field Type="Choice" DisplayName="choice" Name="fldchoice" />', true, SP.AddFieldOptions.addToDefaultContentType),
        var choices = Array("Approved", "Rejected", "Progress");

            Function.createDelegate(this, this.onQuerySucceeded),
            Function.createDelegate(this, this.onQueryFailed)

    function onQuerySucceeded() {
        alert("List Field Updated");

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());


In this example I'm adding SharePoint Choice Field (SP.FieldChoice)  and SharePoint Text Field to existing SharePoint list.

Note: You can you addFieldAsXml and can give complete xml as a string to add the field as well.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sri Lanka Sri Lanka
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 13 Mar 2013
Article Copyright 2013 by Melick
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid