0

I have one SPList -say List1- with some 400 items with single line of text, dropdown, lookup,peoplepicker, multiline fields etc.
I need to copy the entire from this List1 to a new list that has different set of columns.if List1 has 30 columns then my new list List2 has 46 columns. How do I perform this?

I do not have Central Admin access for this application. What should be the approach for achieving this:

  • Should I go with CSOM within a CEWP? If CSOM, can anyone please provide source/links
  • Should I use C# coding, if this is the approach, I can't use Server Side OM as I am not working on the server
    • Just make a list template of the list from site settings, include the content and use the template to create "List2" and add the additional columns. No code needed. – Christoffer Dec 17 '15 at 14:26
    • That wont work.I already tried as my source list columns and target list columns are different. – SaMolPP Dec 17 '15 at 14:30
    • 1
      Sounds like a job for Powershell. – Dylan Cristy Dec 17 '15 at 14:35
    • @SaMolPP, i misunderstood your question. – Christoffer Dec 17 '15 at 14:41
    • @DylanCristy, i don't have access to the server where SP is installed. I have access upto site collec.admin ONLY. So cant think of writing PS Script. – SaMolPP Dec 17 '15 at 15:07
    1

    This only clones/duplicates an item in the currect list, so you have to add

    • Create a second list B (not in this code)
    • loop items in list A (not in this code)
    • create item in list B (n)
    • use while loop (e,f) to loop List A fields
    • write required fields to list B (n,m,v)

      function cloneItem(id) {
      var c = new SP.ClientContext.get_current(),
          l = c.get_web().get_lists().getById(SP.ListOperation.Selection.getSelectedList()),
          i = l.getItemById(id),
          f = l.get_fields(),
          n, e, d, m, v,
          url = _spPageContextInfo.serverRequestPath;
      c.load(i);
      c.load(f);
      c.executeQueryAsync(
          function () {
              n = l.addItem(new SP.ListItemCreationInformation());
              e = f.getEnumerator();
              while (e.moveNext()) {
                  d = e.get_current();
                  m = d.get_internalName();
                  if (!(d.get_readOnlyField() 
                         || d.get_hidden() 
                         || ['Attachments', 'ContentType'].indexOf(m) > -1)
                     ) {
                      v = i.get_item(m);
                      if (v) n.set_item(m, v);
                  }
              }
              n.update();
              c.load(n);
              c.executeQueryAsync(function () {
                  var newID=n.get_id();
              })
          })
      

      }

    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.