in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Scott's blog

Change a Filename using a Workflow

One of the questions that has arisen in our use of SharePoint is this: “How can we automatically change the filename of a document added to a document library?”  We have PDF files that are automatically created in SQL Server Reporting Services, and we want to take advantage of the ability of SSRS to create the files and email them and SP 07 lists to receive emails and add attached documents to the list.  Unfortunately we have not been able to figure out in SSRS how to append a date to the filename, so we turned to SP Workflows to find a solution.

 

Through knowledge gained in training along with a lot of head scratching, we came up with a solution.  It may not be the best solution, but it works for us.

 

1.       Create a column in the target library, name it “Text Date” (or whatever you prefer), set it as single line of text, and calculate the value using the following expression:

=Text([Today], “yyyymmdd”) 

2.       Create a workflow.

3.       Give it a name and select the checkbox for “Automatically start this workflow when a new item is created.”

4.       Click Next.

5.       Add the Action to “Set Field in Current Item.”

6.       Click Field and select “Title.”

7.       Click Value, click the function button, and in the Field drop-down select “Name (for use in forms)”.  This will set the title as the current filename without the file extension.

8.       Add the Action to “Build Dynamic String.”

9.       Click “Dynamic String” and create it as follows using “Add Lookup” (Documents is the name of my target library):

     [%Documents:Title%]_[%Documents:Text Date%].[%Documents:Type%]

10.   Click “Variable: variable1”, “Create a new variable…” and give it a name.  I called mine “FileName”.

11.   Add the Action to “Set Field in Current Item” again.

12.   Click Field and select “Name (for use in forms).”

13.   Click Value, click the Function button, change the source to “Workflow Data”, and change the field to “Variable: FileName”.

14.   Click Finish.

 

Once the Title field has been used to build the FileName variable, it can be rebuilt using any method you see fit.  The “Text Date” field can also be calculated using any date format you wish, however special characters such as / and : cannot be used in a file name.

Comments

 

aL said:

Hey. Nice idea!

What Workflow-Template did you use?

July 20, 2007 2:07 AM
 

ScottM said:

Just the default in SharePoint Designer.

July 20, 2007 2:24 PM
 

Arnold Smith said:

Scott,

We've attempted to duplicate your work on "Change a Filename using a Workflow" but without success. SharePoint doesn't change the Name. The workflow will create a new name and put it into a new custom column, but Name remains inviolate. Any idea what we may be doing wrong?

Thanks,

Arnold

March 14, 2008 3:55 PM
 

ScottM said:

Arnold,

I'm not quite sure without seeing your actual workflow.  I would focus on the last few steps to make sure they are returning valid data, especially the FileName variable.  You might try adding an email to the workflow to send you the text in the FileName variable.

If you would like you can send me a screenshot of your workflow so I can take a look.

Scott

March 20, 2008 3:27 PM
 

Kevin said:

Hi,

This answer also helped me a lot. Except for the fact that I want to do the same, but instead of adding the date automatically, I want to add the string ("new") to a document when it is uploaded for the first time. So I thought I can do the same as you described but it did not work.

Any idea how I can manage this?

Maybe by creating a new column and give it a calculated value? Where the calculated value is something like =Text("new")?

Thanks.

Kevin

April 14, 2008 1:45 AM
 

Valerie said:

Scott,

Arnold was trying to create this workflow for my company's new portal, and now I have taken over the project. I can't produce any results either, and I am following your instructions carefully. In step #9 while creating the dynamic string neither of calculated columns that Arnold and I created appear when using the "add lookup" in the fields dropdown. Current item is chosen. One collumn was created locally by through the list settings, and I created a text date column using site settings>site columns. When looking at the default view of the list, both columns return the expected date value. I think that is the beginning of the problem, none of the custom fields are recognized, any thoughts?

April 18, 2008 12:46 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts