Slinger's Thoughts

March 19, 2009

Tweaking "Copy List item" in SharePoint Designer workflow.

Filed under: SharePoint — slingeronline @ 12:18 pm

I am a huge fan of the custom workflow activities for SharePoint designer that is on codeplex.  I use an abundance of those features, all of which seem to be a shortcoming from Microsoft’s default deployment of SharePoint.  As big of a fan as I am, there are however a few things where they went completely overboard, and made it difficult for a pedestrian user like myself to figure out the ins and outs.  One of the things that I have an issue with is all of the “Copy List Item” functionality.  Microsoft came up short and the guys at codeplex went off the deep end.  Granted, I like having the ability to copy an item to another subsite, site collection, domain, or zip code by using the URL.  I’ve used it in some of my previous posts, like this one.  Sometimes though, I prefer some simpler functionality. 

 One Issue I had recently was a need to copy an item to another list, but to overwrite the item in that list.  By default SharePoint Designer workflows will create a new item if one already exists, and append the time and date to the filename.  I don’t want a new item, I wanted to replace the item already there.  Well, the “Copy List Item Extended” workflow action has the ability to choose whether to overwrite a file or not.  That’s great.  How do I point it to another list in the same site as easily as the regular copy list item works?  I have no idea, other than using the absolute URL of the list.  Well, I’m not really looking forward to having to recreate this workflow 9 times for this site alone, let alone 187,000 times in the near future.  Here’s the problem and my not so elegant solution.

I have a site that has quite a few document libraries in it.  Each one assigned to a different dept.  As a document in each library gets approved, it will need to be copied to another library that has a different permission on it that our client will be allowed to view.  Sounds simple enough, right?  Well, nine different departments have libraries on this site.  So each one will copy a file to this library.  It will fill up quickly with all of the different versions of files, and that just won’t do.  I would prefer that the filename remained the same.  The only issue with this is that if a file has the same name but is from a different document library, there is a chance that one file could be overwritten by a different file from a different library.  I have addressed this with the departments and this is a procedural issue.  They each will have a different document naming convention so it won’t be a problem.  Now the issue is how to get my workflow to overwrite the file instead of adding a new one to the “approved documents” library.  Well first things first, we will need at least two document libraries in our site.  One will represent any of our department libraries and the other will be our destination library.  I’m going to assume that you already know how to create a workflow to copy a file from one library to another, since this is fairly simple.  There are only a few things that I would recommend.  First, instead of using an action and waiting until “Approval Status” = “approved,” I set a condition to check this field.  This does create a little more overhead for the workflow, but it also prevents a mysterious double copy, at least in my environment.  Here’s where I got this to do what I wanted to.  Go ahead and create the workflow and then click “Finish.”  We aren’t finished yet though. We need to edit one little piece of information.  In SPD, navigate to your workflow in the folder list so that you can see the files that make up your workflow.  We need to edit the xoml file just a bit.

ScreenHunter_02 Mar. 19 13.02

Instead of using SPD’s default open action, we want to view the actual xml of the file.  Once you have it open it will probably look similar to this.

ScreenHunter_01 Mar. 19 13.00

You probably can’t see it in that picture, but what we want to change is the property of the “Overwrite” value.  By default, it is false.  If we change that to “True” then our workflow will not append a date and time to the file but it will simply replace whatever file is there that has the same name.  Ideally, it would keep the version history intact, but I don’t know how to accomplish that.  Hope this helps someone else.

About these ads

18 Comments »

  1. Many thanks, this is just the solution I’m looking for, working like a charm!!

    Comment by Samantha — May 11, 2009 @ 5:19 pm

  2. Hmm, doesn’t seem to work for me. Even after setting Overwrite to “True” it still creates a second version

    Any ideas??

    Comment by sayguh — May 13, 2009 @ 12:43 pm

    • Open the workflow with SPD in GUI form again and click finish after saving the xml file with the value change. Then it will work

      Comment by Jay — May 18, 2009 @ 10:14 am

  3. Has anyone got this working, as it’s not working at all for me??

    Comment by David — May 19, 2009 @ 7:51 am

  4. Just what I am looking for, and it works! Many thanks!

    Comment by Joy — July 7, 2009 @ 10:17 pm

  5. HI:

    I tried and it works!!! thanks,

    But I have another problem the first document library have versions and when make the copy and overwrite the document, delete all the last versions.

    How I can do for no delete the versions in the first library document?

    Thanks,

    Comment by Manuel Espadas — September 15, 2009 @ 10:09 am

    • Manuel, unfortunately, that’s the nature of this solution. It will overwrite any version history. Keeping the version history will likely have to be something that someone will need to code as a feature.

      Comment by slinger — September 24, 2009 @ 6:29 pm

  6. anyway to make this work for list items as well as documents? Thanks

    Comment by stephen — September 24, 2009 @ 9:30 am

    • Since a document library is basically a list with attachments, I don’t see why it wouldn’t work with lists. I haven’t tried and haven’t had a chance, but when I do get a chance I will try it out and let you know.

      Comment by slinger — September 24, 2009 @ 6:30 pm

  7. Hi, u know about the copy lookup column to other library?

    Comment by Otto — October 20, 2009 @ 5:57 pm

  8. Your solution for file copy via SPD workflow by changing ‘Overwrite=”False” to ‘Overwrite=”True” then clicking ‘Finish’ from the workflow editor was an absolute godsend after tearing my hair out for a week!! Thank you so much.

    Comment by Gary Drake — April 20, 2010 @ 1:01 am

  9. I can’t get this to work for a SharePoint 2010 list.

    Comment by Matthew Cook — February 29, 2012 @ 11:04 pm

  10. Perfect! Excellent work. I have been searching high an low on how to do this. Was getting frustrated on how it makes a copy with the append date and time. Did what you said and it worked like a charm. Thanks! P.S. – if anyone is having trouble, I ran into a problem where this did not work the first time, and it was because I hit save and then when I tried to publish the workflow it asked me if I wanted to keep the previous version and I said YES which took me back to the overwrite as FALSE, so I redid and this time said NO and it worked just fine. Thanks again. excellent post.

    Comment by Troy Fulkert — May 8, 2012 @ 7:42 am

  11. Does this work for SharePoint 2010 list. any feedback, much appreciated

    Comment by priya — July 19, 2012 @ 10:23 am

  12. Thanks jay for the reply but it does not seem to overwrite in my new list.

    What I want to achieve is once an item is approved, I would like to copy to a new list and overwrite the existing item.

    List One: Judges- ID 1-40
    List two: Judges_V1_Approved– ID 1-40

    Workflow Statement

    If Current Item: Edit Status equals Ready for Approval
    Start approve judges process on Current Item with XX

    Else

    Set Edit Status to Editing

    If variable :IsItemApproved1 equals Yes

    Set Edit Status to Approved
    then Copy item in Current Item to Judges_v1_Approved ( In the Properties, I changed Overwrite to yes)

    Else

    Set Status to Editing.

    Status update is working correctly but instead of overwriting, a new item is added to the “Judges_V1_approved” list.

    Any help on this, greatly appreciate it.

    Comment by priya — July 19, 2012 @ 4:09 pm

  13. Hi, I tried it from document library and it works.
    Only issue I am having is its version number constant. It should increment for each overwrite.

    Any idea how to achieve it.

    Comment by Kishor — May 8, 2013 @ 5:15 am

  14. Hi,

    I had try it in Sharepoint 2010 and seems not to work for me. Am I doing something wrong?

    Comment by Rommel — November 4, 2014 @ 5:08 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Get a free blog at WordPress.com

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: