Hello i try to populate an Array with specific fields. But i always get: 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.
I am on Sharepoint 2013 and i use the internal names from sharepoint. I assume that there is something wrong with my Caml Query.
Here is the Code i use:
function retrieveListItems(siteUrl) {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('MatrixFiles');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><ViewFields><FieldRef Name="LinkFilename" /><FieldRef Name="WebCountry" /><FieldRef Name="WebDepartment" /><FieldRef Name="FileLeafRef" /></ViewFields><Query><OrderBy><FieldRef Name="LinkFilename" /></OrderBy></Query></View>');
this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
And here the other part with the array:
function onQuerySucceeded(sender, args) {
var listItemInfo = '';
var array = [];
var listItemEnumerator = this.collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
console.log(oListItem);
array.push(oListItem);
}
alert(oListItem.get_item('LinkFilename'));
}
The strange thing is the array gets filled with SPListItems but when i try to use a specific field in an alert the error happens. No clue why....
Any help would be great and thx for your Time.
BTW i used the SP Caml Query helper for this.