Slinger's Thoughts

August 13, 2008

two tricks I figured out recently for copying files, part 1.

Filed under: SharePoint — Tags: , — slingeronline @ 9:15 pm

Well, had two issues recently, and solving one introduced the need for the other.  (Our users were completely clueless that I could make SharePoint dance and sing, and send their e-mails for them and, and pour their bourbon and, well you get the idea.)  First up, the whole dilemma that I have had with the difference between a client and a vendor.  Well, I had a post previously about a cross site workflow that solved the problem of how and when to move a file between sites, subsites, or site collections.  The real problem was how to tell SharePoint whereto move the file to.  Well, initially I had set up SharePoint to check a variable and then use that to decide which branch of an if then statement to use to determine where the file should go.  This would be okay for a relatively small number of variables, (for me this was Vendor names), but when you get up to 50, 60 or even 337 vendors, this is suddenly not very effective, and I don’t think that SharePoint can honestly count that high in a workflow.  Basically the workflow had a condition and an action, and then a new branch with a condition and an action, and so on.  I knew there had to be a better way to do it.  There was.

The first thing I did was create two variables in the workflow, one to capture the information in the vendor column, and the other to create a URL for the workflow to use.  (Please note that this solution requires the SharePoint Designer Custom Workflow Activities from Codeplex in order to work.)  Well, I didn’t want the file to always be copied, I only wanted it copied if it was going out, since we keep incoming and outgoing documents in this document library.  So we have a column set to notify where the file is in our system, and I set a condition the workflow to check this column and trigger the action only when the column equals a certain value.  Simple enough so I won’t go into great detail.  Now the fun part.  We need to get a value to set as a variable for our workflow and then we need to apply that variable to another variable.  We are going to use the variables we created a few minutes ago.  So for actions, the first step is to capture that variable.  For me, it was the Vendor’s name.  So, select “set workflow variable.” For “workflow variable” set this to one of the variables we created earlier.  For mine, I have “vendor” obviously enough.  For the second part of this action, where we set the value, select the fxbutton, and then “current item” in the source drop down, and the column that contains the information we want to set as a variable for the field drop down. We have captured the variable that we want to inject, now we need to build a url to tell our workflow where to send this file.  I made an exact copy of the source document library to use as the destination document library on a different site, so that all of the metadata would be identical.  So we have a url to tell our file where to go.  Part of the trick here is to make sure that each potential destination site has the exact same layout.  Transmitted Documents in one vendor’s site needs to be named the exact same thing in every other site.  This is easy enough to do by simply saving a site as a template and then using that to create all of the other sites.  I won’t go into how to do that.  Navigate to the document library that you have created to receive the file and then copy the url for that site.  It will need to be trimmed a bit but we will get to that.  On to building that custom url that we will need for the next step.  Add another action; “Build Dynamic String.” Select “Dynamic String” for this action, and this will bring up an editing window.  Paste the URL that was copied a few minutes ago.  Select the part of the URL that will change depending on which site you want the file sent to and delete it.  For instance, if your URL is
mysite/vendorname/transmitted documents/forms/allitems.aspx, you want to delete vendorname.  Position your cursor between the two / that remain and click on “Add Lookup” in the lower left corner of the editing window.  From the Source dropdown select workflow data, and from the field drop down select the name of the variable that we set in the previous step.  Lastly,, we need to trim the end of the URL, because the forms/allitems.aspx will confuse SharePoint and our workflow will fail.  Make sure that you do leave the trailing / in our custom URL however.  When looking at the dynamic string it should resemble something not too dissimilar from
http://mysite/%5B%Variable: Vendor%]/transmitted documents.  Click “OK” and now we have a dynamic URL that will be determined by our metadata column variable.  The last thing we need to do is copy the file to our new URL.  This will be almost the same as when we did this previously, with one exception.  For this action click on “This url” and instead of entering a URL in manually, we are going to select the variable we just created. Click on the fx button, and select “workflow data” for the source, and the name of the variable we just created for the “field.”  That should be it.  Check the workflow for errors, save it, and then take it out for a test drive. 

Some things to watch out for though, are little variances in the column we capture information from.  Vendorname is not the same as Vendor name. A way that I have found to combat this is to make this column a dropdown list and not a text box when entering metadata.  I also don’t want to be editing tons of lists, so I have created a list that my users can edit that contains vendor information, but I have also set an alert on each one of these columns so that I can monitor entries here and correct them so that my custom URL doesn’t break.  It’s a nice touch and makes the job of one of our most documentation intensive departments much easier.

Stay tuned for part two that also deals with the Approval workflow, and how to use that in combination with automatically copying a file.


1 Comment »

  1. […] 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 […]

    Pingback by Tweaking "Copy List item" in SharePoint Designer workflow. « Slinger’s Thoughts — March 19, 2009 @ 12:18 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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at

%d bloggers like this: