我需要一个 SharePoint 工作流,当文件上传到单独文档库(帐户文档)中的特定文件夹时,该工作流将更新列表(帐户跟踪器)项目。文件夹的名称将对应于列表中要更新的行。
举个例子:
- 用户将文档上传到“帐户文档”库内的“实体 1”文件夹。
- 工作流程会根据“Accounts Documents”库中的文件夹名称自动更新“Accounts Tracker”中标题为“Entity 1”的行。
问题是工作流程如何引用库中的文件夹名称来更新列表中的正确行?
最佳答案
所以,如果我理解正确的话,目标是获取添加文档的父文件夹名称,然后使用该名称更新以该名称作为标题的列表项。
工作流程中最复杂的部分是获取父文件夹名称。
包含文档的文件夹名称是变量当前项目:服务器相对 URL 的一部分。
您可以在工作流程中使用一系列事件从服务器相对 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
您需要将更新列表项事件添加到工作流程后。
在查找列表项部分中,使用ParentFolderName变量检索目标列表元素。
希望这有帮助!
---一些问题的解答
循环的第一行仅用于解释? 是的。在工作流程中添加循环时,您还可以添加注释。所以“直到找到最后一个斜杠”只是一条注释
循环的第二行 - 如何“在变量中查找/”? 在工作流中,您有一个查找字符串变量中的字符的事件。它类似于 JavaScript 中的indexOf。在此工作流程中,我们需要找到斜杠“/”字符。请记住,目标是获取 URL 内的父文件夹。我们可以通过搜索 URL 中的最后一个斜杠来找到它。
循环的第 9 行 - 有多少个字符? 0 是我的工作流程中的默认值。 字符数将自动计算。查找名为 IndexPlus1 的变量
第四行检查 - 我在工作流程上下文中没有可用的“列表名称” - 我可以使用“关联名称”吗? 我不知道你无法获取列表名称的原因。也许您可以尝试创建另一个 SP 2013 工作流程,看看是否遇到同样的问题?
检查第五行 - “根文件夹”是否硬格式化,即不是查找? 是的。根文件夹是硬编码的。
关于sharepoint-2013 - SharePoint 工作流根据单独文档库中的文件夹名称更新列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41829008/