I am trying to use JavaScript to get all the items in a document library. I am able to get it to work, but for the life of me I cannot get the title, name or path to the file to come back. I can get ID, modified and any other custom columns I have on the list.
I have used the code right from the sharepoint api. but here it is if you wanna see it
function getRowsFromList(LIST_URL, LIST_GUID, RETURN_FIELDS, params)
{
var clientContext = new SP.ClientContext('/team');
var oList = clientContext.get_web().get_lists().getByTitle('KML');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Leq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>100</Value></Leq></Where></Query><RowLimit>50</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();
var arr = [];
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
var File = oListItem.get_file();
listItemInfo += '\n ID: ' + oListItem.get_id() +
'\n Name: ' + oListItem.get_item('Title');
arr.push(oListItem.get_id());
}
alert(listItemInfo.toString());
buildMenu(arr);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
I am calling my function like this...
ExecuteOrDelayUntilScriptLoaded(init, "sp.js");
I am linking my js through the master page like this...
<SharePoint:ScriptLink language="javascript" name="sp.js" OnDemand="true" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink language="javascript" name="sp.runtime.js" OnDemand="true" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink language="javascript" name="sp.core.js" OnDemand="true" runat="server" LoadAfterUI="true" Localizable="false"/>
<SharePoint:ScriptLink language="javascript" name="core.js" OnDemand="true" runat="server" LoadAfterUI="true" Localizable="false"/>
Please let me know if you have any questions... No error gets thrown, the value that returns is just null, when thats not the case.