Skip to content

Instantly share code, notes, and snippets.

@rjesh-git
Created October 20, 2015 21:24
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 rjesh-git/1a8ebb90ae7dfbb7fc82 to your computer and use it in GitHub Desktop.
Save rjesh-git/1a8ebb90ae7dfbb7fc82 to your computer and use it in GitHub Desktop.
var exportExcel = function () {
var selecteditems = SP.ListOperation.Selection.getSelectedItems();
currentListGuid = SP.ListOperation.Selection.getSelectedList();
var context = SP.ClientContext.get_current();
currentSite = context.get_site();
currentWeb = context.get_web();
var currentList = currentWeb.get_lists().getById(currentListGuid);
listitemidDict = '';
for (var index in selecteditems) {
listitemid = currentList.getItemById(selecteditems[index].id);
listitemidDict = listitemidDict + selecteditems[index].id + ',';
}
context.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailure));
};
var onSuccess = function () {
var form = document.createElement("form");
form.setAttribute("method", "post");
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "IDDict");
hiddenField.setAttribute("value", listitemidDict);
form.appendChild(hiddenField);
var hiddenListGuid = document.createElement("input");
hiddenListGuid.setAttribute("type", "hidden");
hiddenListGuid.setAttribute("name", "ListGuid");
hiddenListGuid.setAttribute("value", currentListGuid);
form.appendChild(hiddenListGuid);
var hiddenViewGuid = document.createElement("input");
hiddenViewGuid.setAttribute("type", "hidden");
hiddenViewGuid.setAttribute("name", "ViewGuid");
hiddenViewGuid.setAttribute("value", ctx.view);
form.appendChild(hiddenViewGuid);
form.setAttribute("action", "http://localhost:3000/export");
document.body.appendChild(form);
form.submit();
SP.UI.Notify.addNotification('Exported Successfully');
};
var onFailure = function (sender, args) {
var statusId = SP.UI.Status.addStatus(args.get_message());
SP.UI.Status.setStatusPriColor(statusId, 'red');
latestId = statusId;
};
var exporttoexcelenable = function () {
return (true);
};
var listitemid,
listitemidDict,
currentWeb,
currentSite,
currentListGuid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment