Wednesday, December 30, 2015

SharePoint Get List Attachments



SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
debugger;
 var ctx=new SP.ClientContext("http://nit-hv5-idm2:11111/sites/hr/referral");
  var list = ctx.get_web().get_lists().getByTitle("Job Opening");
 var query = new SP.CamlQuery();
     query.set_viewXml('');
 var listFields = list.getItems(query);
 ctx.load(listFields);
ctx.executeQueryAsync(Function.createDelegate(this, function(sender,args){
debugger;var i=0;
   var listEnumerator = listFields.getEnumerator();
  while (listEnumerator.moveNext()) {
if(i++ == 0){
    var oField = listEnumerator.get_current();
    var attachments = oField.get_attachmentFiles();
    ctx.load(attachments);

ctx.executeQueryAsync(Function.createDelegate(this, function(sender, args){
debugger;
var enums = attachments.getEnumerator();
while (enums.moveNext()) {
var attacha = enums.get_current();
console.log(attacha.get_serverRelativeUrl());
}
 
console.log(attachments);
 

}), Function.createDelegate(this, function(){}));  

}
 }
}), Function.createDelegate(this, function(){}));
});

No comments:

Post a Comment