Search This Blog

Wednesday, August 2, 2017

One List to Another List Insert multiple item with Folder Sharepoint 2013

Step 1: Add Script Editor in your page
Step 2: Change ListName ,Site Name
Step 3: Paste Below code

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>One List to Another List Inser</title>
    <link rel="stylesheet" href="//">
    <script src="//"></script>
    <script src="//"></script>
    <script type="text/javascript">

        //We need to run our function only after sp.js file loads
        ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
        function ViewItem() {
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            var list = web.get_lists().getByTitle('testList');

            //It will fetch all the items from the list
            var myquery = new SP.CamlQuery.createAllItemsQuery();
            myquery.set_viewXml("<View><Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query><RowLimit>5</RowLimit></View>");
            myItems = list.getItems(myquery);
            //If the items load correctly then success function will be called
            context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
        var newObj = { data: [] };
        function success() {
            var ListEnumerator = this.myItems.getEnumerator();
            while (ListEnumerator.moveNext()) {
                //Will get the current row from the SP List
                var currentItem = ListEnumerator.get_current();
                    "ID": currentItem.get_item('ID'),
                    "Title": currentItem.get_item('Title')

        function failed(sender, args) {
            alert("failed. Message:" + args.get_message());
        function createListItem() {

            var contextz = new SP.ClientContext.get_current();
            var web = contextz.get_web();
            var oList = web.get_lists().getByTitle('testList2');
            var itemCreateInfo = new SP.ListItemCreationInformation();
            // need to specify full path after site domain , ex:         
            var newItem = null;
            $.each(, function (key, item) {
                newItem =  oList.addItem(itemCreateInfo);             
                newItem.set_item('Title', item.Title);
                //set values to other columns of the list here
            contextz.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        function onQuerySucceeded() {

        function onQueryFailed(sender, args) {
            alert("failed. Message:" + args.get_message());

    <div class="ui-widget">      
        <input id="Submit1" type="submit" onclick="createListItem();" value="Submit Item in Folder" />


No comments:

Post a Comment