Sharepoint 2013

Get Attachments using SPServices in SharePoint 2013

Sharing is Caring

[sourcecode language=”javascript”]

$().SPServices({

operation: "GetListItems",
async: false,
listName: "listname",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
$().SPServices({
operation:’GetAttachmentCollection’,
listName: "listname",
ID: $(this).attr("ows_ID"),
completefunc: function (xData, Status) {
$(xData.responseXML).find("Attachments").each(function() {
alert($(this).text());
});
}

});
});
}
});[/sourcecode]

But theres a much more better way to do it,Thanks to Marc:

[sourcecode language=”javascript”]
var p = $().SPServices({
operation: "GetListItems",
listName: "listname",
CAMLQueryOptions: "<QueryOptions>" +
"<IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls>" +
"</QueryOptions>"
});

p.done(function() {

$(p.responseXML).).SPFilterNode("z:row").each(function() {

var attachments = [];

var att = $(this).attr("ows_Attachments");
if(att !== "0") {
attachments = att.split(";#"); // Now you’ll have an array of attachment URLs
} else {
// att will be "0", indicating that there are no attachments
}

});

});
[/sourcecode]

Have fun 🙂