1

Following is my code:

retrieveListItems('https://sustec29-public.sharepoint.com');

function retrieveListItems(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Announcements');

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
    '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
    '<Value Type=\'Number\'>1</Value></Geq></Where></Query>' + 
    '<RowLimit>10</RowLimit></View>'
);
this.collListItem = oList.getItems(camlQuery);

clientContext.load(collListItem);
clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded), 
    Function.createDelegate(this, this.onQueryFailed)
); 
}

function onQuerySucceeded(sender, args) {
    var listItemInfo = '';
    var listItemEnumerator = collListItem.getEnumerator();

while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();
    listItemInfo += '\nID: ' + oListItem.get_id() + 
        '\ngroup: ' + oListItem.get_item('group') + 
        '\ndisc: ' + oListItem.get_item('disc');
}    
        $('#message').text(listItemInfo.toString());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

But browser gives 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."

If I write

        '\ntitle: ' + oListItem.get_item('title') + 
        '\nbody: ' + oListItem.get_item('body');

and rename field table's - all ok.

But I want add my own field.

0

The message:

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

stands for that not all list item properties have been retrieved.

SP.ClientContext.load method is overloaded and the method also accepts a second parameter for specifying the properties that have to be loaded. In your example, please try to specify fields explicitly:

clientContext.load(collListItem,"ID,Title,Body,group,disc");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.