How to duplicate a Sharepoint list item

I was trying to add a duplicate link to the list item menu dropdown context box, so that user can click and duplicate an item. It’s actually quite easy to do that.

First, what we need to do is add the C# code so that when the item is saved, we check if there is a request query string of relevant item ID. If there is, that means this is going to be duplicated. So the logic works as follow:

if Request Query String 'DID' exists
    get the item by DID
    for each fields of this item, we add its value to current to-be-created item
    update current item

That’s about it. Now, to add the link to the List Menu, we simply add a Content Editor Web part with the following JavaScripts:

function Custom_AddListMenuItems(m, ctx) {
    CAMOpt(m, "Duplicate", 
       "window.location = 'NewForm.aspx?DID="+ currentItemID+"'", 
       "/_layouts/images/copy.png");
    CAMSep(m);
}
Tags: