1

I wanted to be able to have a button that would create a new record (new ID number) with the same data that was in the record I chose to create a new one off of. So a user wouldn't have to re-type all of the data in if they would like to change one thing.

So essentially I want to be able to clone a item into a new record.

Any help would be appreciated

0

In the past, I just used a manually initiated workflow that would copy the list item into the same list as a new item. This suited the need pretty well. Easy, straight forward.

  • are you talking about going into editing list mode, and copying the entire line of data into a new line? – Matt Ludwig Apr 15 '15 at 13:34
  • No, a workflow could be triggered from the ribbon or the ECB that then copies the line data to a new line. – Eric Alexander Apr 15 '15 at 13:41
  • Anyone have a idea? – Matt Ludwig Apr 17 '15 at 19:20
0

You can do this via CSOM or JSOM or SSOM. Below is an example using JSOM

var clientContext = new SP.ClientContext(siteUrl);
var web = context.get_web();
context.load(web);
var oList = context.get_web().get_lists().getByTitle('Copy');
context.load(oList);
var selectedItems = SP.ListOperation.Selection.getSelectedItems(context);

var currentItem = source.getItemById(selectedItems[i].id);
context.load(currentItem);
context.executeQueryAsync(Function.createDelegate(this,CreateNewItem),Function.createDelegate(this,error));

function CreateNewItem(sender, args){
    var itemCreateInfo = new SP.ListItemCreationInformation();
    var oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('Title', currentItem.get_item('Title'));
    oListItem.update();
    oList.update();
}
  • how do I use jsom? I never tried this.. – Matt Ludwig Apr 15 '15 at 13:33
  • You can do this using a Script Editor WebPart. It is basically client side code. – Amal Hashim Apr 15 '15 at 13:34
  • so add a new web part (script editor) in my view form and copy the above code into it? – Matt Ludwig Apr 15 '15 at 13:36
  • Yes you can add the web part in your form. This code won't work straight away. You need to add a HTML button tag and then hook up the click event. Then get the current item id and then use that to get the item by id etc. – Amal Hashim Apr 15 '15 at 13:37
  • anyone can assist please? – Matt Ludwig Apr 15 '15 at 18:19

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.