When assigning tasks in SharePoint workflows, you may have noticed that each task that gets assigned has one field that associates it with the original list or library item where the workflow task came from. You may have noticed the “Related Content” column in a task list. It is just a hyperlink field that links you back to that original item.
This post applies to SharePoint enterprise, and SharePoint Online for Office 365 (enterprise version).
In my experience, it’s quite challenging to do any kind of filtering and reporting just based off of a hyperlink field. And web part connections won’t even work with this field, it’s just not very useful except for just as a link to click back to that item.
What if you want to have a lookup field that goes back to the original item, or other metadata information?
In this post, I’ll show you how to create other task fields and set up the workflow so that it populates those fields when each task gets created.
My document library is called Shared Documents, and the task list is Tasks. When tasks are assigned for people to approve the documents in the library, I want a field called “LookupSharedDocument” to be populated for each task.
- Create a site column called LookupSharedDocument, as a lookup field. Make it lookup to that Shared Documents library. Pick the Title column in the drop-down. We can also pull info from any other fields in that library, so put a check box next to “modified”. Click OK. You can be creative here, and check the box next to any other fields that you’d like to see listed in the task list.
- Open your site in SharePoint Designer.
- Click Workflows on the left, and create a new workflow based on the Shared Documents library. Name your workflow “test approval”.
- Add a single action to your workflow Start Approval Process.
- Click on the blue these users.
- Since it’s just a test, you can put your own name in the Participants box. In the real world, this would be the name of the person or group who will be assigned the task.
- Next to Title, click the little ellipsis […] button. Type:
- Click the Add or Change Lookup button, and pick the Title field from the current item. Click OK. I put a “1” next to Duration per task, since I only want each person to have one day to complete their task.
- Click OK on all dialog boxes until you’re back at the workflow screen.
- Click the blue word Approval. For the name, change it to Document Approval.
- On the right in the Task Form Fields section, click Choose Existing field. Click OK to the notification message.
- IMPORTANT: Be sure and click the Publish button to publish your workflow before doing the next part, because once this lookup field is added to the task form, it won’t re-generate the form, and you’ll get the error at step 15. This won’t happen with other fields besides lookup fields, though.
- Choose the LookupSharedDocument field, and click OK.
- Click Change the behavior of a single task.
- Put your cursor in the top step called Before a Task is Assigned. Add the action called Set Task Field. Note that this is NOT the same as set field in current item, and inside of this task process inside of this one step, you’ll have actions available here that aren’t available in other parts of the workflow.
- Click the blue word FIELD. Choose LookupSharedDocument.
- Click the blue word VALUE. Pick the ID field from the current item.
- Click the Publish button at the top, to publish your workflow to SharePoint.
Note: I got an error about not being able to generate the task form or something, but I clicked OK, and I was still allowed to publish the workflow. The error just means that it won’t create the new Lookup field in the task form itself. But since we don’t want people editing it, we would have removed it anyway.
- Open your task list in the browser, and modify the default view to add the two new columns for the Lookup… information.
Now in the drop-down box for a document in Shared Documents, click Workflows, and click your Test Approval workflow. Click to START the workflow. A task will immediately be assigned to you. Take a look over in the task list, and notice that the new columns now have the lookup information in them!
Now go to your Shared Documents library, and click to edit the page (of just the default view). On the ribbon, click the Insert Related List button in the Web Part Tools (Options) tab. Notice that it lets you select that tasks list!!
This is a great solution, not just for lookup fields, but for any additional task fields that need to be populated with information from the original list or library. I just recommend creating them as site columns first. In this case, we were just looking up the ID of the current item, but there could be a case where you have a field like customer code or something, that’s just a text field in the shared documents library. You’d need to create it as a site column first, before adding it to the document library. Then, when you’re at step 11, you’d be choosing that exact same site column to put in your tasks list.