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