Various ECMA List field operations in SharePoint 2013/2016

In the SharePoint client object model, ECMA plays key role. I would like to walk you through various methods to access list fields or columns using ECMA scripting.

ECMA script client object model is nothing but same as the JavaScript client object model also known as JSOM in SharePoint.

Note: Like as in the C# object model, in ECMA also we need to use the SharePoint list field internal name.

ECMA List field operations in SharePoint 2013/2016

This is the default filed will get created as soon as we create a SharePoint list with Item content type. To read Title field

To read value: ObjListItem.get_item(‘Title’)
To set value: ObjListItem.set_item(‘Title’, “Title Value”);

The default column get creates with the list and it is an auto incremental field.

To get ID: ObjListItem.get_id()

URL/Hyperlink Field: In SharePoint URL field will have to set 2 values 1 is URL and the other one is description.

To get URL value – ObjListItem.get_item(‘urlfieldname’).get_url()
To set URL value – ObjListItem.set_item(‘urlfieldname’,”URL field Value”)
To get description value – ObjListItem.get_item(‘descriptionfieldname’).get_description();
To set description value – ObjListItem.set_item(“descriptionfieldname”,”description Value”);

Setting Hyperlink Field from UI:
Below is the way you can set hyperlink field through UI in SharePoint 2013.

sharepoint ecmascript

Hyperlink list field:

ecmascript sharepoint

Version Details:
To get the version details of a SharePoint list item.

To read the version details: ObjListItem.get_item(“_UIVersionString”)

Choice field:
In SharePoint, we have a field to facilitate selecting a single value from a list of values.

To get the value: ObjListItem.get_item(‘ChoiceFieldName’)
To set the value: ObjListItem.set_item(‘ChoiceFieldName’,’Choice Value’)

ecmascript sharepoint 2013 examples

Created Date:
SharePoint creates the default time stamp as soon as list item get created.

To get the time stamp: objListItem.get_item(“Created”)

Modified Date:
SharePoint also tracks updated date time.

To get the updated timestamp: objListItem. get_item(“Modified”)

Created User Name:
As we learned just before SharePoint keep track of all the operations and user accounts operated with. This will get the Created User Name.

To get the created User Name: objListItem.get_item(“Author”).get_lookupValue()

Modified User Name:
Now that we learned to get the created user, the below will get the modified user name.

Modified User Name: objListItem.get_item(“Editor”).get_lookupValue()

List Item Content Type:
As we learned at the beginning of the article list will get associate with one content type. If we need to know the content type associated with the list item.

To know the Content Type: objListItem.get_contentType()

You may like following SharePoint client object model tutorials:

Hope this helps, happy development in the SharePoint Object model.