2

I need to create a workflow that simply duplicates a list item and adds it to the same list. (when item is created). I know that there is the function in SP Designer 2010, but Im not allowed to use this functionality since I should create it with SP Designer 2013 only. Is there a good workaround for that? Best solution would be a web service to do it, but im not that familiar with it. I think this articel leads to the right direction, but there is still something missing and Im not 100 % sure what it is actually doing.

http://mysharepointinsight.blogspot.de/2013/05/using-sharepoint-rest-services-from.html

Can somebody privde me some help?

1
  • Be careful, your workflow might quickly fill your list with thousands if not millions of copies of the same list item unless you make it understand which item is created by a human and which is already a copy. May 23, 2017 at 4:14

3 Answers 3

2

Not Workflows but JSOM code

Get the ID of the item you want to clone (in the current context) and execute:

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 () {
                document.location = url.substr(0, url.lastIndexOf('/')) 
                                     + '/EditForm.aspx?ID=' + n.get_id();
            })
        })
}

SO Answer: Set default values in new controls on custom form

Executes it from a List View:

1

If I understood correctly you would like to create the same item via a Workflow in the same list?

Then you can select under Actions -> Create New List Item -> and then just set Title and all you columns to the current item and the field.

No need to work with REST here.

Do not forget to check the box "Run on item created"

1
  • that would be one solution, but the workflow should be rather generic, since it should be used for several lists :) Dec 1, 2015 at 14:03
0

How about using custom workflow action to do this

How to: Build and deploy workflow custom actions https://msdn.microsoft.com/en-us/library/office/jj163911.aspx

Walkthrough: Create a Custom Site Workflow Activity https://msdn.microsoft.com/en-us/library/ee231574.aspx

Your Answer

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

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