Pages

Sunday, August 16, 2015

Get Values of SharePoint List Item Fields using ECMAScript (JCOM)

This post has described for you that how to read values of different field types of SharePoint lists using ECMAScript(JavaScript Client Object Model).

ID – SP.ListItem.get_id();

Title – SP.ListItem.get_item(‘Title‘);


Description – SP.ListItem.get_item(‘[DescriptionFieldName]‘).get_description();


Choice Field – SP.ListItem.get_item(‘[ChoiceFieldName]‘);


Url -SP.ListItem.get_item(‘[UrlFieldName]‘).get_url();


Lookup field – SP.ListItem.get_item(‘[LookupFieldName]’).get_lookupValue();


Lookup field – SP.ListItem.get_item(‘[LookupFieldName]’).get_lookupId();


Created Date – SP.ListItem.get_item(“Created“);


Modified Date – SP.ListItem.get_item(“Modified“); -> case sensitive does not work with ‘modified’


Created By – SP.ListItem.get_item(“Author“).get_lookupValue();


Modified by – SP.ListItem.get_item(“Editor“).get_lookupValue();


Current Version – SP.ListItem.get_item(“_UIVersionString“);


File  – SP.ListItem.get_file();


File Versions -  File.get_versions();.


Content Type – SP.ListItem.get_contentType();


Parent List – SP.ListItem.get_parentList();

Note:When you querying for LookupField, if it has allow multiple values(in column settings in SharePoint) you may get return an array of values as the result instead of a single value. In this scenario you need to loop through an array and get the results item by item.

Here is the way to do that:


loop through array:

for(var i=0; i< SP.listItem.get_item('[LookupFieldName]').length; i++)
{
     SP.listItem.get_item('[LookupFieldName]')[i].get_lookupValue();
     or
     SP.listItem.get_item('[LookupFieldName]')[i].get_lookupId();
}

first item:

SP.listItem.get_item('[LookupFieldName]')[0].get_lookupValue();
or
SP.listItem.get_item('[LookupFieldName]')[0].get_lookupId();

No comments:

Post a Comment