-
-
Save ahsanranjha/4b88c0931d2d188b7532890377ec6a39 to your computer and use it in GitHub Desktop.
The example demonstrates how to move list item into folder via SharePoint JSOM API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listTitle = "Requests"; //list title | |
var itemId = 1; //list item id | |
var targetFolderUrl = "/Lists/Requests/Archive"; //target folder server relative url | |
var ctx = SP.ClientContext.get_current(); | |
var list = ctx.get_web().get_lists().getByTitle(listTitle); | |
var item = list.getItemById(itemId); | |
ctx.load(item,['FileRef','FileDirRef']); | |
ctx.executeQueryAsync( | |
function(){ | |
var fileUrl = item.get_item('FileRef'); | |
var file = ctx.get_web().getFileByServerRelativeUrl(fileUrl); | |
var targetfileUrl = fileUrl.replace(item.get_item('FileDirRef'),targetFolderUrl); | |
file.moveTo(targetfileUrl, SP.MoveOperations.overwrite); | |
ctx.executeQueryAsync( | |
function(){ | |
console.log('List item has been moved'); | |
}, | |
logError | |
) | |
}, | |
logError); | |
function logError(sender,args){ | |
console.log(args.get_message()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment