Slinger’s Thoughts

March 19, 2009

Tweaking "Copy List item" in SharePoint Designer workflow.

Filed under: MOSS, SharePoint, SharePoint Designer, Workflow — slinger @ 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.

10 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


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.