I have a reusable workflow on library to fill the values in a list. I also want to get library name value to be filled in list' one column. Probably using stringbuilder and using some string manipulation on the url of current library Any idea?
While you cannot get the list TITLE this way, you should at least be able to get the list URL through a somewhat round-a-bout way. It will require two new columns on your content type and a new step in the workflow:
- Create a new site column (single line of text) and call it "Path"
- Add the new "Path" column to your content type
- In your reusable workflow, add a new step that sets the field "Path" in the current item to the relative URL of the current item, minus whatever you can strip off like web app URL and/or document name. Note: There are third-party workflow extensions that can make extracting a substring easier.
- Add a new site column (calculated column) to your content type and call it "LibraryPath"
- In your calculated column formula, use a combination of FIND and LEFT/RIGHT to strip off any remaining parts from the item's absolute URL. In the end, you should have only the list URL left (ex - "SharedDocuments"). When stripping out URL parts, you can usually use "/" as your waypoint.
For a full list of the text functions available in a calculated column, click here. Unfortunately, you will need to figure this part out yourself since every URL is different. Basically, you want to count the number of characters until a slash, then strip out that number of characters (+1 to remove the slash as well).
UPDATE: Here is a blog post showing how you can use Excel to test your formulas before putting them into a calculated column.
Also, please note that if you're accessing the full range of columns behind a library - such as with XSLT - there is a column called @FileDirRef which returns only the site-collection-relative URL of the library. Unfortunately, this column isn't available to either a calculated column or a SharePoint Designer workflow.
UPDATE 2: Also, keep in mind that a third-party workflow system, such as Nintex Workflows, may allow you to simply extract the current library name right off the bat. You can also do this via the SharePoint API if coding your own workflow in Visual Studio. Vanilla SharePoint does not offer this functionality, however.
UPDATE 3: Last one, I promise. If your workflow is 2013 compatible, you may be able to get the current list/library name through a web service call in your workflow. I've never tried getting this value specifically, so I'm not sure. Here is a reference to using the functionality.
Related Question: Get string out of url in calculated column
If you're developing the workflow in Visual Studio, you can use the following code to access the Title property of the Item's Parent List.
// Get the item the workflow is running on. SPListItem item = workflowProperties.Item; // Get it's parent list/library title. string libraryTitle = item.ParentList.Title.ToString(); // Set the column value. item["Library Title"] = libraryTitle; // Commit the changes. item.Update();
If you don't want to update modified/modified by or create a version use the following instead of
yes, it is possible to get the name of the list/library in Reusuable workflow:
1) create a association parameter (LibraryName) from 'Initiation Form parameters' option.
2) Then associate your workflow with the list/library it will ask for the parameter (LibraryName), enter the name and click on ok.
3) log/use the variable(LibraryName) in the workflow.