2
votes

I need a SharePoint workflow that will update a list (Accounts Tracker) item when a file is uploaded to a specific folder in a separate document library (Accounts Documents). The name of the folder will correspond to the line to be updated in the list.

So, as an example:

  1. User uploads document to 'Entity 1' folder within 'Accounts Documents' library.
  2. Workflow updates a line in 'Accounts Tracker' with the title 'Entity 1' is automatically based on the folder name in the 'Accounts Documents' library.

The question is how does the workflow reference the folder name in the library to update the correct line in the list?

1

1 Answers

2
votes

so, if I understand correctly, the goal is to get the parent folder name in which the document as been added then use that name to update a list item with that name as title.

The most complex part of your workflow will be to get the parent folder name.

The name of the folder containing the document is part of the variable Current Item:Server Relative URL.

You can use a series of activities in your worklow to extract the folder name from the Server Relative URL.

Stage: Find Folder Name
    Step: Set variables
        Set Variable: FilePAth to Current Item:Server Relative URL
        then Set Variable: TrimmedFilePath to Variable: FilePath
        then Set Variable: index to 0
        then Set Variable: LastIndexOf to -1
        then Set Variable: PreviousLastIndexOf to -1
    Loop: until last slash is found
        The content of this loop will run repeatedly while Variable: index is greater than or equal to 0
            Find / in Variable: TrimmedFilePath (Output to Variable: index)
            If Variable: index is greater than or equal to 0
                If Variable: LastIndexOf not Equals -1
                    Set Variable: PreviousLastIndexOf to Variable: LastIndexOf
                then Calculate Variable: LastIndexOf plus 1 (Output to Variable: LastIndexOf)
                then Calculate Variable: LastIndexOf plus Variable: index (Output to Variable: LastIndexOf)
                then Calculate Variable: LastIndexOf plus 1 (Output to Variable: IndexPlus1)
                then Copy from Variable: FilePath, starting at Variable: IndexPlus1 (Output to Variable: TrimmedFilePath)
    Step: Check foldername
        Calculate Variable: PreviousLastIndexOf plus 1 (Output to Variable:PreviousLastIndexOfPlus1)
        then Calculate Variable: LastIndexOf minus PreviousLastIndexOfPlus1 (Output to Variable:FolderNameLength)
        then Copy from Variable: FilePath, starting at Variable: PreviousLastIndexOfPlus1 for Variable: FolderNameLength characters (Output to Variable: ParentFolderName)
        If (Variable: ParentFolderName equals Workflow Context:List Name)
            Set Variable: ParentFolderName to Root Folder

After you need to add a Update List Item activity to your workflow.

In the Find the List Item section, use the ParentFolderName variable to retrieve the target list element.

Hope this help!

--- Answers to some questions

1st line of Loop is for explanation only? Yes. When you add a loop in a workflow, you can also add a comment. So « until last slash is found » is just a comment

2nd line of Loop - how do I "find / in variable"? In a workflow, you have an activity to find characters in a string variable. It's something similar to indexOf in JavaScript. In this workflow, we need to find a slash « / » character. Remember that the goal is to get the parent folder inside a URL. We can find it by seaching for the last slash inside the URL.

9th line of Loop - how many characters? 0 is default on my workflow. The number of charaters will be calculated automaticly. Look for the variable named IndexPlus1

4th line of Check - I don't have "List Name" available in Workflow Context - can I use "Association Name"? I dont' know the reason why you can't get the list name. Maybe you can try to create another SP 2013 workflow and see if you get the same problem?

5th line of Check - is "Root Folder" hard formatted i.e. not a lookup? Yes. Root Folder is hard coded.