I have a SharePoint 2013 list TestList. Each record of my list has three attachments... I am trying to get the links of each attachment and display it in a table using jQuery. Is it possible?
My code:
var id;
$().SPServices({
operation: "GetListItems",
listName:"Test",
webURL:"http://sharepoint.pfizer.com/sites/test/",
CAMLViewFields: '<ViewFields><FieldRef Name=\'ID\'/></ViewFields>',
async: false,
completefunc: function (xData, Status)
{
$(xData.responseXML).find("z\\:row, row").each(function()
{
id=parseInt($(this).attr("ows_ID"));
ExecuteOrDelayUntilScriptLoaded(getWebProperties, "SP.js");
var attachmentFiles;
function getWebProperties() {
var itemId=id;
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
var attachmentFolder=web.getFolderByServerRelativeUrl('Lists/Test/Attachments/'+itemId);
attachmentFiles= attachmentFolder.get_files();
ctx.load(attachmentFiles);
ctx.executeQueryAsync(Function.createDelegate(this,this.onSuccess),Function.createDelegate(this,this.onFailed));
}
function onSuccess(sender, args) {
var i=0;
for(var file in attachmentFiles) {
alert(attachmentFiles.itemAt(i).get_serverRelativeUrl());
i++;
}
}
function onFailed(sender, args) {
alert("Not found!");
}
});
}
});