2

I have requirement in my SP 2010 Site's SPlist and get all the items including attachments(docx files are attached with all these list ite,s - listitem count is 5500 ) using javascript and client object model and i need to insert these list items into the O 365 -SPO - team site's splist.

Steps I have done: Created a content editor web part in SP 2010 site page Wrote the code for getting all items from splist am stuck with how to insert these list items , along with attachments int SPO site's list?

  // load all necessary sharepoint javascript libaries
          SP.SOD.executeFunc('sp.js', 'SP.ClientContext',   function () {
    // load the sharepoint list.
        loadSharepointList();
     });
   // loads the sharepoint list
        function loadSharepointList() {
        // create the sharepoint content.
    var context = SP.ClientContext.get_current();
    // get the list by the title.
    var list = context.get_web().get_lists().getByTitle('Sample List');

// create the query.
    var caml = new SP.CamlQuery();
    caml.set_viewXml(''); 

// get the list items asynchronously
  var listItems = list.getItems(caml);
  context.load(listItems , 'Include(Title)');
    context.executeQueryAsync(

    // success delegate
    Function.createDelegate(this, function() {

    // loop through the items.
        var listEnumerator = listItems.getEnumerator();
        while (listEnumerator.moveNext()) {

            // get the current list item.
            var listItem = listEnumerator.get_current();

            // get the field value.
            var fieldValue = listItem.get_item('Title');
        }
        }),
        // error delegate
    Function.createDelegate(this, function() {
        alert('Error fetching data from Sharepoint!');      
    }));
    }

1 Answer 1

3

I think you should use CSOM code instead of JSOM as JSOM will not able to create separate client context object for SPO within SP2010 but this can be possible in CSOM where you can create two separate client context object one for SP2010 and another for SPO, then you can easily migrate your data from SP2010 to SPO

All the best

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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