7

Uncaught 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.

Even after explicitly including the item, I am still receiving the error message above. It works perfectly for a test list that I made, however it does not work on my primary list.

​​​​​​​​​

// Get the current Site
var siteUrl = 'www.example.com/';

function retrieveListItems() {    
    console.log("Test");

    var clientContext = new SP.ClientContext(siteUrl);
    // Get the liste instance
    var oList = clientContext.get_web().get_lists().getByTitle('CAS Pre-Project');

    var camlQuery = new SP.CamlQuery();

    // Get only the last element
    camlQuery.set_viewXml('<Query><OrderBy><FieldRef Name=\'ID\' Ascending=\'False\' /></OrderBy></Query><RowLimit>1</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    //clientContext.load(collListItem);
    clientContext.load(collListItems, 'Include(PPID)');

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

        var listItemInfovalue = oListItem.get_item('PPID');
        console.log(listItemInfovalue);

        var res = listItemInfovalue;
        console.log(res)            

        var newId = parseInt(res)+1;

        SPUtility.GetSPField('PPID').SetValue(newId);
    }

    console.log(listItemInfo.toString());
}

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

$(document).ready(function(){
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js"); 
});

​​​​​​​​​​​​​​​​​​​​​​​​​

At this point I am out of ideas of what to try and I have tried everything that I have seen. Any help will be appreciated!

-Patrick

2 Answers 2

5

You'll certainly need to change clientContext.load(collListItems, 'Include(PPID)'); to clientContext.load(collListItem, 'Include(PPID)');

collListItem is different than collListItems

If that doesn't work, I would log a list object in the response into my developer console to double check my results...

Add a line like: console.log(collListItem.getItemAtIndex(0).get_fieldValues()) at the top of the success method and see what values you're getting with the returned results in the javascript console.

0
0

Double check that the column 'PPID' has not been renamed on your list. You might also try dropping and then recreating that column to be sure the name is consistent.

Columns have what's called an internal name and a display name. I suspect the internal name for your column in production is incorrect. Here is some more information: Finding the internal name and display name for a list column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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