0

I need to copy attachments from list in subsite to list in main site.

I dont have any idea how to start and as far I know and what I have search, you cant use wf because it wont work.

So does anyone have any idea or maybe solutions?

  • Are you trying to create something you are going to do it frequently? Or is this a one time thing you have to execute? – Amal Hashim Oct 19 '17 at 12:00
  • More then one time so its frequently. – Slavenko Oct 19 '17 at 12:06
0

If its a one time job then you can Save the List with content as a Template and restore it in your main site.

More traditional approach is to use the Site Content and Structure page to move the list items from sub site to root site.

This can also be achieved using JSOM.

  1. To trigger the move - Add a button to a page and hook the click event

    <input type="button" value="Move List Items" id="btnMove"/>
    $(document).ready(function() {
        $("#btnMove").click(function(){
            MoveListItems();
        }); 
    });
    
  2. Now you can use JSOM to load the list items along with the attachments from source list

    function MoveListItems() {
        var ctx = SP.ClientContext.get_current();
        var web = ctx.get_web();
        var list =  web.get_lists().getByTitle(listTitle);
        var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
        ctx.load(items,'Include(AttachmentFiles)'); 
        ctx.executeQueryAsync(
            function() {
                for(var i = 0; i < items.get_count(); i++){
                    var item = items.getItemAtIndex(i);
                    //print attachments
                    var attachments = item.get_attachmentFiles();
                    for(var j = 0; j < attachments.get_count(); j++){
                        var attachment = attachments.getItemAtIndex(j);
                        console.log(attachment.get_serverRelativeUrl());
    
                        //Logic to Upload the attachment to Main List
                    }   
                 }  
            },
            error
        );
    }       
    
  3. For each list item - using JSOM create a new list item in Target List

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.