I am attempting to write a generic function for appending list items to an html table so that I can create a consolidated list of files across multiple document libraries. I am able to pass parameters into the getListItems method but I have no idea how I might pass a value to the completefunc function.
Does anyone have any suggestions? (see use of thisFirstColumn in completefunc)
Does anyone have any suggestions? (see use of thisFirstColumn in completefunc)
$(document).ready(function(){
getListItemsGeneric("https://site", "first column text", "my library name");
function getListItemsGeneric(listUrl, firstColumn, listName){
var thisUrl = listUrl;
var thisFirstColumn = firstColumn;
var thisListName = listName;
$().SPServices({
operation: "GetListItems",
webURL: thisUrl,
async: false,
listName: thisListName,
completefunc: function (xData, Status) {
//alert("Status of XML message reaching Sharepoint webservice: " + Status);
//alert("Response from server: " + xData.responseXML.xml);
$(xData.responseXML).find("[nodeName=z:row]").each(function() {
//find the title. use filename if title is not populated
strTitleField = $(this).attr("ows_Title");
if(!strTitleField){
strTitleField = $(this).attr("ows_LinkFilename");
}
strDocumentLink = $(this).attr("ows_FileRef");
strDocumentLink = "https://myserver/" + strDocumentLink.substring(strDocumentLink.indexOf(';#')+2, strDocumentLink.length);
strCat1 = $(this).attr("ows_Category_x0020_1");
if(!strCat1) {
strCat1 = '';
}
strCat2 = $(this).attr("ows_Category_x0020_2");
if(!strCat2) {
strCat2 = '';
}
var Html = "<tr>";
Html += "<td>" + thisFirstColumn + "</td>";
Html += "<td><a href='" + strDocumentLink + "' target='_blank'>" + strTitleField.replace(/_/g,' ') + "</a></td>";
Html += "<td>" + strCat1 + "</td>";
Html += "<td>" + strCat2.substring(0,30) + "</td>";
Html += "</tr>";
$('#tableid').find('tbody').append(liHtml);
});
}
});
}
});