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.
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
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.
Hyperlink list field:
To get the version details of a SharePoint list item.
To read the version details: ObjListItem.get_item(“_UIVersionString”)
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’)
SharePoint creates the default time stamp as soon as list item get created.
To get the time stamp: objListItem.get_item(“Created”)
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:
- SharePoint 2016 crud operations using Rest API and jQuery on list or document library
- Update People Picker Group field using Rest API and jQuery in SharePoint 2013/2016
- Make Title field read-only in SharePoint list edit form using JSLink
- Remove DIV tag from Multiline text field using ECMA
- Send Email with jQuery and REST API in SharePoint
- How to set lookup column value in SharePoint 2013/2016 ECMA Script
- unable to get property ‘getenumerator’ of undefined or null reference SharePoint
- Upload attachment to a new item on the list using REST API JQuery in SharePoint 2013
- $(document).ready(function() not working SharePoint 2013/2016 list form
Hope this helps, happy development in the SharePoint Object model.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019