Skip to content

Instantly share code, notes, and snippets.

@premchandpl
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save premchandpl/9cfa05a7efc4ed86264e to your computer and use it in GitHub Desktop.
Save premchandpl/9cfa05a7efc4ed86264e to your computer and use it in GitHub Desktop.
var createItemWithAttachments = function(listName, listValues){
var fileCountCheck = 0;
var fileNames;
var context = new SP.ClientContext.get_current();
var dfd = $.Deferred();
var targetList = context.get_web().get_lists().getByTitle(listName);
context.load(targetList);
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = targetList.addItem(itemCreateInfo);
listItem.set_item("FirstName", listValues[0].FirstName);
listItem.set_item("LastName", listValues[0].LastName);
listItem.update();
context.executeQueryAsync(
function () {
var id = listItem.get_id();
if (listValues[0].Files.length != 0) {
if (fileCountCheck <= listValues[0].Files.length - 1) {
loopFileUpload(listName, id, listValues, fileCountCheck).then(
function () {
},
function (sender, args) {
console.log("Error uploading");
dfd.reject(sender, args);
}
);
}
}
else {
dfd.resolve(fileCountCheck);
}
},
function(sender, args){
console.log('Error occured' + args.get_message());
}
);
return dfd.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment