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.
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.
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.