SharePoint Workflow Solutions – Problem 1. Assigning Tasks Dynamically.
I am starting a series of articles about the ways I have solved some typical workflow implementation problems in SharePoint Designer and perhaps in VS2005/2008. These posts are not based on the technology itself but on solving a problem. Therefore, there can be as many solutions as programmers / process designers who face it. If you know a smarter, faster, or recommended way to solve it, please send me a comment.
(Keep in mind that:
a. these solutions focus on being able to transfer knowledge to non-developer users and using only the out-of-the-box tools available
b. it is assumed that the user already uses InfoPath, SharePoint Designer, Visual Studio 2005, and SharePoint.)
Problem 1. The first (or the second or the nth) task in a workflow is assigned dynamically depending on information filled in by the user.
This is a typical scenario. The organization has 50 managers. In the form there is a field that identifies the area to which the expense is assigned; the expense approval activity must be assigned to the manager of that area.
Solution.
Preparing the Data Source.
1. Create a list in SharePoint called _Areas. (The name has a “_” character to help me identify the lists I will use as data sources).
2. In this list create a field called Name (string), eMail (String), Account (User/Group)
3. In this list create the 50 managers.
Connecting the Data Source to the Form.
(In this case the form is made with InfoPath; other scenarios may require connecting the data entry to the list created earlier).
1. In InfoPath create a data source, in the Tools/Data Connections menu.
2. Add a new connection, select the data source as a SharePoint list. Find the areas list you created. Give the data connection a name. Done; if you edit it you should see something like this:
3. The data source is now available for the whole form. Select a field, in this case manager, which is a dropdown that can be seen in the previous image, and configure that field's data source with the connection I just created. It should look something like this.
Well, now when the user fills out the form they can select the manager who authorizes this or the area to which the expense belongs in this case. This information will be stored as a field in the SharePoint document library associated with this form. With that information we can now make decisions.
Create Workflow.
Well, now in SP Designer you can use the new workflow option, select the document list on which you want to run the workflow (which must be the same one fed by the form we created earlier), and you arrive at the workflow steps wizard window.
Enjoying this? Get more like it, once a week.
Create the Action within the Workflow Step (Activity).
Ok, now for the solution,
1. Create an action of type Set Workflow Variable.
2. Click on workflow variable, select create new variable, you can give it a name like PreApproveUser, of type string.
3. Click on value and on the function option. That opens the value assignment window, which is occasionally a bit complicated to use, so here is a photo of the final result and an explanation of what this means
i. Select the list from which I want to get the information, in this case _Departments, then which variable I want, AD Name in this case, then I tell it how I want to obtain that information, for example, that when the manager in the _Departments list equals the manager in the procurement list.
ii. Sometimes it is easier to think of it as a SQL select; it would be like this: select AD User from _Departments Where _Departments:Manager = Procurement Manager.
4. So now I have the AD user name in a workflow variable called PreApproveUser, and I can use that variable to send emails, assign tasks, etc.
5. I create a new action of type Collect User Data. I build the information I want to collect and assign the task to the PreApproveUser variable.
6. As always, I must assign the result of the task to a workflow variable.
7. I continue the process….
In this way a common process development problem with SharePoint Designer can be solved: dynamic assignment of tasks based on information entered by the user. This example also serves to illustrate other interesting things, such as the use of data sources in SharePoint forms.
Juan Carlos Peláez
Software Architect.
keywords: sharepoint designer, infopath, bpm, problemas comunes workflow, juan pelaez, fuentes de datos en infopath, variables de workflow, wss 3.0, moss 2007.
Need Expert Help?
Let's discuss how I can help with your technical challenges
Schedule a Consultation