Copy the below snippet and paste it in your environment and call this function in your script.
- function movedoc() {
- var files = [];
- var context = SP.ClientContext.get_current();
- var web = context.get_web(); context.load(web);
- var targetlib = web.get_lists().getByTitle('ArchiveFolder');
- context.load(target);
- var notifyId;
- var currentlibid = SP.ListOperation.Selection.getSelectedList();
- var currentLib = web.get_lists().getById(currentlibid);
- var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);
- var count = CountDictionary(selectedItems);
- if (count == 0)
- {
- alert('Please choose at least one file to move from Draft Folder.');
- }
- for (var i in selectedItems)
- {
- var currentItem = currentLib.getItemById(selectedItems[i].id);
- context.load(currentItem); var fle = currentItem.get_file();
-
- files.push(fle);
- context.load(fle);
- }
- context.executeQueryAsync(
- function (sender, args)
- {
- for (var i = 0; i < files.length; i++)
- {
- var File = files[i];
- if (File != null)
- {
- var targetlibUrl = web.get_serverRelativeUrl() + '/' + 'Documents' + '/' + File.get_name(); File.moveTo(targetlibUrl, 1);
- notifyId = SP.UI.Notify.addNotification('Moving file ' + File.get_serverRelativeUrl() + ' to ' + _destinationlibUrl, true);
- context.executeQueryAsync(
- function (sender, args)
- {
- SP.UI.Notify.removeNotification(notifyId); SP.UI.Notify.addNotification('File moved successfully', false);
- },
- function (sender, args) {
- SP.UI.Notify.addNotification('Error moving file: ' + args.get_message(), false);
- SP.UI.Notify.removeNotification(notifyId);
- });
- }
- }
- }, function (sender, args) {
- alert('Error occured' + args.get_message());
-
- }
- });