How to read a column type SPUser, DateTime, Currency with EcmaScript?

£可爱£侵袭症+ 提交于 2019-12-04 19:37:22
Shegit Brahm

Okay, I got a solution Sharepoint.Stackoverflow.com from user Vardhaman Deshpande. This works.

Here is How to get the value of each type of field:

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();

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

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());

File  – SP.ListItem.get_file();

File Versions -  File.get_versions();.

Content Type – SP.ListItem.get_contentType();

Parent List – SP.ListItem.get_parentList();

from: http://www.learningsharepoint.com/2011/07/06/how-to-get-various-item-fields-using-client-object-model-ecmascript-sharepoint-2010/

UPDATE: The following code is working and tested.

var item;
function getItemById(itemId){

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

    var web = clientContext.get_web();

    var list = web.get_lists().getByTitle('myList');

    item = list.getItemById(itemId);

    clientContext.load(item);

    clientContext.executeQueryAsync(onSuccess, onFailure);
}
function onSuccess(){

    alert(item.get_item("My User column").get_lookupValue());
}
function onFailure(){

    alert('Failure!');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!