Create Site Column Using JSOM in SharePoint Online

Create Site Column Using JSOM in SharePoint Online

In this article, i describe you, To Create Site Column Using JavaScript Object Model(JSOM) in SharePoint or SharePoint Online. I already told you in my previous post, To Create Site Column using CSOM.

In SharePoint, site column is the reusable column which can be used across multiple SharePoint List within a site. A site field can be used in the same site collection or its subsite hierarchy.Below is code to Create Site Column Using JSOM in SharePoint Online.

[AdSense-A]

<input type='button' value='Create Site Column' onclick="SiteColumnCreation();"/>
 <script>
        function SiteColumnCreation() {

            var ColumnSchm = "<Field DisplayName='CustomColumnName2' Name='CustomColumnName2' Type='Text'/>";

            var Contx = new SP.ClientContext.get_current();

            var fields = Contx.get_web().get_fields().addFieldAsXml(ColumnSchm, false, SP.AddFieldOptions.addFieldCheckDisplayName);

            Contx.load(fields);

            fields.set_group("SPCOLUMNCustom");

            fields.updateAndPushChanges(false);

            Contx.executeQueryAsync(CreateSuccess, failure)
        }

        var CreateSuccess = function () {
            alert('Site column has been created successfully !!!');
        }

        var failure = function () {
            alert('Something went wrong while creating site column.');
        }
    </script>

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!