1

I'm trying to create a workflow in SharePoint Designer that will automatically rename files as they are created/uploaded in various document libraries, to a pre-determined 'item ID' pattern. The idea is that all the documents in one library might be called DOC-0001, DOC-0002, DOC-0003...

The information required to generate an ID for each library is stored in a list called ID prefixes, which contains the prefix (DOC- in this case), the length of the ID and the next available number. The GUID of the library is also stored to allow the workflow to look up the next available ID from a calculated column in the ID prefixes list.

In order to prevent errors occurring due to duplication I have a document in another library called Workflow Edit Tokens, which the workflow must check-out before issuing an item ID. I am using a SharePoint 2013 workflow so that multiple instances of the workflow will wait until this token is checked back in before proceeding. SharePoint 2010 workflows will fail with a 'cancelled' status if the token is already checked out, and if this isn't used at all the workflows will attempt to rename multiple files the same item ID.

The problem I'm having is that the only column I can save data to using a reusable workflow (there are many document libraries that will use this workflow) is Title. Name (filename) is not available, and hence I can't rename the files at all.

At the moment the only option I can see is to manually create the workflow for each document library. Can anyone suggest a way of changing the Name column from a SharePoint 2013 reusable workflow, or alternatively a way of queueing SharePoint 2010 workflows so conflicts don't occur?

Thanks, Jon

  • Another option is to rename the title and link the file to that as mentioned in this question: sharepoint.stackexchange.com/questions/158227/… – Akhoy Oct 7 '15 at 5:43
  • I had considered something like that, but I'm concerned about obfuscating the actual filename, which could lead to new files accidentally overwriting old ones. – Jonathan Holvey Oct 7 '15 at 22:07
  • It will not do anything to the file. You are just setting value to a huperlink column title and linking that with the file. Like my answer here: sharepoint.stackexchange.com/a/158246/13799 – Akhoy Oct 8 '15 at 5:37
  • I realise that the file won't be modified, but my concern is that without having control over the filenames, documents could accidentally be overwritten when uploading in the future. Also, when files are downloaded they'll still have the filename they were uploaded with. The reason for my question was because I want to control the filenames, not just the view link. – Jonathan Holvey Oct 9 '15 at 6:31
1

In the end I used the REST API from within the workflow to rename the file. I did this by first retrieving the file's properties from a HTTP GET request to:

https://example.SharePoint.com/_api/web/lists/getByTitle('Test Library')/items(12)

where Test Library is the name of the library and 12 is the ID of the file to be renamed. This string can be built in SharePoint Designer like so:

[%Workflow Context:Current Site URL%]_api/web/lists(guid'[%Workflow Context:List ID%]')/items([%Current Item:ID%])

I then made a POST request to the same URL in order to rename the file. In the body of that request I included the d["__metadata"]["type"] value returned from the first call, and the new file name in a property called (rather obscurely) FileLeafRef:

{
    "__metadata": {
            " type": "SP.Data.Test_x0020_LibraryItem"
    },
    "FileLeafRef": "New File Name"
}

The headers Content-Type: application/json; odata=verbose, X-HTTP-Method: MERGE and If-Match: * are required for this API call.

0
  1. Create a calculated column in your list a that creates the name you want the file to be renamed to

  2. Create a workflow

Action: If Current Item Field:Name is not empty Update List Item

List: CurrentItem Field: Path and Name
Value: [%CalculatedColumnName%]

3.On the Update List Item dialog box, click OK.

  1. Set workflow to start when new item is created
  • This doesn't work since the only field available in the Update List Item action is Title. Note that I'm using a reusable workflow, not a list workflow, so only fields from the Item content type are available to update. – Jonathan Holvey Jun 23 '16 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.