I try to get the value of a list item (that is currently selected). I know that I must load it into the context but even with loading the field explicitly I get the following message.
Microsoft JScript runtime error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Here is what I used to test if I can get to the field values:
function showTitles(urlColumnName) {
var selectedItemIds = getSelectedItemIds();
for (var ii = 0; ii < selectedItemIds.length; ii++) {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var lists = web.get_lists();
var list = lists.getById(SP.ListOperation.Selection.getSelectedList());
var item = list.getItemById(ii);
context.load(item, "Title");
context.executeQueryAsync(Function.createDelegate(this, getAndShowTitle(item, urlColumnName)),
Function.createDelegate(this, showError));
}
}
function getAndShowTitle(item, urlColumnName) {
var title = item.get_item("Title");
alert(title);
}
function showError(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
It even fails with "Title". (UrlColumnName is not really used in this example). The functions are all in the same JS file and I don't use any global vars (for the item storage) but besides from that I don't see any difference to some working examples I found on the web.
The exception occurs on: var title = item.get_item("Title");
Any ideas what I'm missing?