In this below script,get field values ECMA Script/Javascript using CSOM
SharePoint client object model used to retrieve, update, and manage data in SharePoint 2013.
Types:
1.Server Object Model
2.Client Object Model
3.Javascript Library
4.Rest Service/OData Library
Loads the SP.Runtime.js and SP.js files by using the getScript function in jQuery.
Title – SP.ListItem.get_item('Title');
ID – SP.ListItem.get_id();
Url -SP.ListItem.get_item('urlfieldname').get_url()
Description – SP.ListItem.get_item('descriptionfieldname').get_description();
Current Version – SP.ListItem.get_item("_UIVersionString");
Lookup field – SP.ListItem.get_item('LookupFieldName’).get_lookupValue(); // or get_lookupID();
Created By – SP.ListItem.get_item("Author").get_lookupValue();
Modified by – SP.ListItem.get_item("Editor").get_lookupValue();
Choice Field – SP.ListItem.get_item('ChoiceFieldcolumnName');
Created Date – SP.ListItem.get_item("Created");
Modified Date – SP.ListItem.get_item("Modified"); -> case sensitive does not work with 'modified’
File – SP.ListItem.get_file();
File Versions - File.get_versions();.
Content Type – SP.ListItem.get_contentType();
Parent List – SP.ListItem.get_parentList();
Note: ('LookupFieldName’).get_lookupValue() sometimes returns an array of data, especially when your lookup allows multiple values.
For this,you will need to iterate the array and get each value individually.
SP.ListItem.get_item('LookupFieldName’)[0].get_lookupValue();
For Arrays:
for(var i = 0; i < oListItem.get_item("LookupFieldName").length; i++)
{
alert(oListItem.get_item("LookupFieldName")[i].get_lookupId()); // or get_lookupValue()
}
No comments:
Post a Comment