Reputation: 242
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.
Upvotes: 0
Views: 1304
Reputation: 26
Try using FileLeafRef. LinkFilename is a computed field which does not work.
msdn - Not able to search list using LinkFileName
Upvotes: 1
Reputation: 38
I imagine this error is occurring because the sp.js script has not been loaded.
Try:
//Insert this right after your opening script tag
ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
//then your function as written above
function retrieveListItems(siteUrl) { etc...};
Also this answer may be helpful: SharePoint 2013 add javascript after whole page load
Upvotes: 1