The following instructions
describe the process of creating a workflow that interacts with
multiple SharePoint lists when items are created and modified. The
workflow is based on three lists: a Region list, a Sales Lead list, and a
Customer list. When a user marks a sales lead as SaleClosed, a manager
can trigger the workflow and create a customer based upon the data in
the Sales Lead list. This workflow also demonstrates how to work with
SharePoint lookup columns by copying the salesperson from the Region
list and adding the value to the customer list.
Although limited, this
example demonstrates the steps necessary to develop a relatively simple
application using SharePoint Designer. The functionality is limited
because the processes are asynchronous, and the lists can only be joined
by a single column, but the general concept could be reused for a
variety of business purposes. Generally, a quickly developed application
built in SharePoint is an easier sell to business owners than a
standalone .NET application that requires everything from an IIS site,
security, documentation, and even its own database. Furthermore, the
following example can be extended with list item security, custom views,
custom forms, and email notifications to make the application more
fully featured.
Follow these steps to create the application using SharePoint Designer 2010:
1. | In
a nonproduction site collection, create three SharePoint lists with a
Standard View (Do not use Datasheet View) using the Custom List template
with the columns and data types, as shown in Tables 1, 2, and 3. Unless specified in these tables, leave the other settings for the columns and the list on their defaults. Table 1 provides the columns needed for the Region list, Table 2 provides the columns needed for the Sales Leads list, and Table 3
provides the columns needed for the Customer list. Several of the
columns are specified as Required to maintain data integrity within the
application; if fields are allowed to be left blank, the application may
not function properly.
Table 1. Region List Columns and SettingsColumn | Data Type | Require That This Column Contains Information |
---|
Title | Single Line of Text (Already Present) | Yes | Salesperson | Person or Group | Yes |
Table 2. Sales Leads List Columns and SettingsColumn | Data Type | Require That This Column Contains Information |
---|
Title | Single Line of Text (Already Present) | Yes | Region | Lookup Column—Link to Region List’s Title Column | Yes | SaleClosed | Yes/No with Default Value set to No | No |
Table 3. Customer List Columns and SettingsColumn | Data Type | Require That This Column Contains Information |
---|
Title | Single Line of Text (Already Present) | Yes | Region | Lookup Column—Link to Region List’s Title column | Yes | Salesperson | Person | No | Customer ID | Single Line of Text | No |
Note
Leave the lists blank at this point. They will be populated after the workflow is created and full instructions are provided.
| 2. | Browse
to the home page of the site housing these lists, and from the IE File
menu, click Edit with Microsoft SharePoint Designer. If this option
doesn’t exist, open SharePoint Designer manually, and then select Open
Site and enter the URL for the site that houses these lists (such as
http://abcsp1004/sites/spdtest). Provide credentials if asked.
| 3. | Next,
select the Workflows entry from the Navigation pane, Site Objects
section on the left side of SharePoint Designer, and then select the
drop-down menu under List Workflow in the Workflows tab that should be
active. Click Sales Leads list, as shown in Figure 1.
| 4. | Name the workflow Sales Leads–On Change. Click OK.
Tip
When creating a workflow, it is
good practice to provide a name that identifies the underlying list and
if the workflow is triggered On Change, Manually, or On Create.
| 5. | Upon
creation of a new workflow, the workflow editor screen appears with a
blank canvas containing a single step named Step 1. Click within the
Step 1 editor box in the section under the title bar to ensure it is
active, and then click the Condition button on the Workflow Ribbon and
choose the Condition If Current Item Field Equals Value. Step 1 will now
reflect this change and display If Field Equals Value.
| 6. | Click the field link that now appears in Step 1, and select SaleClosed from the drop-down list.
| 7. | Then click the value link, and select Yes from the drop-down list. Figure 2 shows the contents of the step at this point.
| 8. | Next
add an action just below the condition created. Click in the Step 1 box
below the row where the Condition was just defined. Type Create and press Enter, and choose Create List Item from the options.
| 9. | Click the This List link that will now be visible to open the Create New List Item window.
| 10. | Choose Customer from the drop-down menu List field at the top of the window. Figure 3 shows the results.
| 11. | In the Create New List Item window, double-click the field Title to open the Value Assignment window.
| 12. | In the Value Assignment window that opens, click the fx button and the Lookup for Single Line of Text window opens.
| 13. | In the Lookup for Single Line of Text window, select Title in the Field from Source field, as shown in Figure 4.
| 14. | Next,
click OK to close the Lookup for Single Line of Text window, and click
OK to close the Value Assignment window. The Create New List Item window
should be active. The Title (*) entry in the Field column now has a
Value entry of Current Item:Title.
| 15. | In the Create New List Item window double-click the field Region to open the Value Assignment window.
| 16. | In
the Value Assignment window, click the fx button to open the Lookup for
Integer window. Verify that the Data Source field has Current Item in
it.
| 17. | Change the value for the Field from Source to Region.
| 18. | Choose Lookup Id (as Integer) for the Return Field As field. The completed Lookup for Integer window looks like Figure 5.
| 19. | Click
OK in the Lookup for Integer window and again in the Value Assignment
window to return to the Create New List Item window. Now the Create New
List Item window has a value assigned to the Region (*) field of Current
Item:Region.
| 20. | In the Create New List Item window, click the Add button to open the Value Assignment window.
| 21. | In the Value Assignment window, specify Salesperson for the Set This Field drop-down list.
| 22. | Click the fx button to open the Lookup for Person or Group window.
| 23. | Change the value in the Data Source field to Region and additional fields appear.
| 24. | In the Field from Source field, select Salesperson from the drop-down menu.
| 25. | In the Return Field As drop-down menu, verify that As String is selected.
| 26. | In
the Find the List Item section of the Lookup for Person or Group
window, select Title in the Field drop-down list, as shown in Figure 6.
| 27. | To
complete the Lookup for Integer window, click the fx button for the
Value field to open the Lookup for Single Line of Text window.
| 28. | In the Data Source field, leave Current Item selected.
| 29. | In the Field from Source field, choose Region from the drop-down menu.
| 30. | In the Return Field As drop-down, choose Lookup Value (as Text) from the drop-down menu. Click OK.
| 31. | The Lookup for Person or Group window will now be complete and look like Figure 7.
| 32. | Click
OK to close the Lookup for Person or Group window, and click Yes when
the message The Lookup You Defined Is Not Guaranteed to Return a Single
Value appears. Click OK to close the Value Assignment window.
| 33. | The Create New List Item window should now look like Figure 8 and include a Salesperson field with a value of Region:Salesperson.
| 34. | Click OK to close the Create New List Item window.
| 35. | Save the workflow by clicking the Save button on the Workflow tab of the SharePoint Designer Ribbon.
Note
Unlike SharePoint 2007
workflows that were immediately active upon save, SharePoint 2010
workflows are only available for use after they are published.
|
To publish the SharePoint Designer workflow designed so far, follow these steps:
36. | Click the Workflow Settings tool on the Ribbon, and the display changes to show the workflow settings.
| 37. | Verify that Allow This Workflow to Be Manually Started is selected from the Start Options section in the lower-right side.
Note
The workflow can be
configured to start automatically, but the logic in this example is
that the list item may be changed many times, and a user might
accidentally set the item to Closed; a manager should be the only one
starting the workflow, after the manager has confirmed that the lead is
closed.
| 38. | Click the Publish button on the Workflow tab on the Ribbon to deploy and activate the workflow on the list.
Tip
A form will be visible on
the Workflow Settings page that should be titled “Sales Leads – On
Change.xsn.” Clicking this link opens InfoPath 2010 if installed on the
computer and enables customization of the initiation form.
|
Testing the Workflow
Immediately
after saving and publishing the workflow it’s ready for testing. To
test the Sales Lead workflow, follow these steps to populate the
necessary lists and start a workflow:
1. | Return
to the SharePoint site where the workflow was published and the three
custom lists are present. (In this example, the site is
http://abcsp1004/sites/spdtest.)
| 2. | Access the Region list and add two items. The first item should be titled Region A and have a salesperson assigned who is a valid AD user account (such as User1 in this example). The second item should be titled Region B and have a different salesperson (such as User2 in this example).
| 3. | Next, access the Sales Leads list on the SharePoint site. Click Add New Item; fill in the title with Customer ABC
and select Region A. Click Save. This simulates the process of a field
being created for a sales prospect in a specific region. In a production
situation, additional fields could be added to track conversations with
the client or upload proposals and other documents to the list item.
| 4. | Next,
edit the Sales Lead item created in the previous step, and check the
SaleClosed check box; then click Save. This simulates the event where
the sale is closed and the lead is ready to be converted to a customer.
| 5. | Next, access the drop-down menu for the item, and click Workflows.
| 6. | The Sales Leads – On Change workflow should appear next to the workflow icon and should display as shown in Figure 9. Click the link next to the workflow icon to access the initiation page.
| 7. | The IniWrkflIP.aspx page loads. Click the Start button.
| 8. | You
return to the Sales Leads list and a column appears titled Sales Leads –
On Change, which indicates that the workflow is In Process and then
Completed.
| 9. | Navigate to the customer list and verify that a new item has been created, as shown in Figure 10.
| 10. | Return
to the Sales Leads list, and click the value that appears in the
workflow column to view the workflow history for that particular list
item. The workflow history window opens and displays the status for the
latest instance of the workflow.
|
Extending the Capabilities of the Application
Although the previous
workflow will function properly, it is just a starting point and would
not generally be considered to be “enterprise ready.” Following are some
items to consider as ways of enhancing the functionality of the
application:
Create custom list views to show and hide the sales leads depending on whether the lead is actually closed. Create an alert in the Sales Leads list that alerts a manager when an item that is set to SaleClosed equals Yes. Create
a new workflow that starts when an item is added to the Customer list
that sends an email to the assigned salesperson to alert her that she
has a new client. For
testing purposes, add the workflow action Log to History List to output
debug or informational messages to the workflow history screen. Logically,
the application has flaws because if a sales lead were reopened and
then marked as Closed again, the workflow would trigger and create a
duplicate customer; therefore, a condition should be added to step 1
that checks for the existence of the customer through the use of a
lookup on the customer’s title column.
|