2. Implementing a Visio Workflow Using SharePoint Designer
In the preceding section, you saw how to model a
workflow using Visio and create an interchange file that can be
imported into SharePoint Designer. In this section, we’ll move on to
flesh out the logic defined in Visio using the built-in workflow
activities available via SharePoint Designer.
In SharePoint Designer, select Workflows from the Site Objects pane.
In the Workflows ribbon’s Manage section, click the Import From Visio button.
Browse to the PublishingProcedure.vwi file that we created in the preceding section. Click Next to import the file.
In the Import Workflow From Visio Drawing dialog, type the Workflow name as Product Publishing.
Two different workflow types are available: List Workflow and Reusable
Workflow. The main difference between these workflows is that the List
Workflow is attached to a particular list and cannot be used by
multiple lists, whereas a reusable workflow can be bound to any number
of lists or content types. List workflows provide comparable
functionality to SharePoint Designer workflows in MOSS 2007. Choose
Reusable Workflow as the type, and then from the content types
drop-down, select Product. The completed dialog will look like the
following illustration. Click Finish to complete the import process.

Once
our Visio model has been imported, SharePoint Designer will create a
new workflow named Product Publishing and will automatically open the
workflow editor, shown next, where we can complete the configuration of
the workflow.

The
logic steps from our Visio model have been automatically inserted into
our SharePoint workflow, and hyperlinked terms in each step allow us to
finalize the configuration. In the Collect Technical Details from
Engineering Department step, click the data
hyperlink so that we can define exactly what data should be collected.
In the Custom Task Wizard that appears, click Next to begin creating a
new task.
Name the new task Collect Technical Details. Click Next to add fields for the data in which we’re interested.
Add a field and name it Technical Data.
Set the Information Type to Multiple lines of text. Click Next, accept
the default columns settings, and then click Finish to add the field.
Click Finish to complete the Custom Task Wizard.
Using Workflow Variables
Now
that we’ve created a custom task to capture data, we need a way to
retrieve the data that we’ve captured so that we can do something
useful with it. As its name suggests, the Custom Task Wizard creates a
task with a custom form. When a user completes the form, any data
captured is stored in the associated task. The output of this step is
an identifier for the task item that was created. As you’ll see later,
we can use this to pick up a reference to the task and from there
access any data that was captured in our custom form.
You’ll remember reading about workflow rules and
variables. Since we need to use our task identifier in another step of
our workflow, we must create a variable and assign the output to it.
To
add a new variable, click the Local Variables button from the Workflow
ribbon. Add a new variable named TechnicalDetailsTaskId with a type of
List Item Id, as shown next. Click OK.
To assign the output of our Collect Technical Details task to our new variable, click the (Output to collect) hyperlink and then select Variable:TechnicalDetailsTaskId.

Use the Custom Task Wizard to add a Collect Product Image from Marketing Department step. This time, add a field and name it Product Image of type Hyperlink or Picture and uncheck the Allow Blank Values option in Column settings. Add a variable named ProductImageTaskId to store the output of the task.
Now that we’ve configured our data capture tasks, the only item remaining is the approval action. Click the this item hyperlink to select the items that should be the subject of the approval process. In our case, it should be the Current Item.
With these configuration changes in place, our revised workflow should look like this:

Using Initiation and Association Forms
You’ll notice that a few properties still need to be
configured. These properties contain details of the users to which each
task should be assigned. Generally speaking, properties such as these,
which are likely to change over time, should be user-configurable—that
is, the user should be able to change them without having to edit the
underlying workflow. SharePoint workflows provide two forms for user
configuration: the Association form, which is presented when a workflow
is attached to a list, and the Initiation form, which is presented when
a workflow is manually started.
There’s one thing to bear in mind when using the
initiation form: it’s not shown if the workflow is started
automatically. So, for example, if we created a workflow that was set
to start every time an item changed, the initiation form would never be
shown.
In the case of our workflow, an association form is
a more appropriate choice, because it allows us to define parameters
that can be set at the list level.
To
define a parameter that appears on an association form, click the
Initiation Form Parameters button in the ribbon. Add a new field named Engineering Department
with an Information type of Person or Group. In the Collect From
Parameter During drop-down, select Association (Attaching To A List).
In the Column Settings dialog, uncheck the Allow Blank Values option
and select the All Users radio button in the Choose From section. Click
Finish to add the parameter.
Repeat step 1 and add a Marketing Department parameter and an Online Sales Manager parameter.
To bind these parameters to our workflow actions, click the this user
hyperlink. Since we’re binding to a parameter rather than an actual
user, select Workflow Lookup for a User. Click Add to configure the
parameter binding. In the Lookup for Person or Group dialog, select
Workflow Variable and Parameters as the Data source. Our association
form parameters can now be selected from the Field From Source
drop-down. Select the appropriate parameter and then click OK to
complete the binding.
Repeat
step 3 to bind all association form parameters to our workflow actions.
The completed workflow should look as illustrated:

Using the SharePoint Designer Lookup Dialog
Although we’ve configured the actions that were
imported from Visio, the end result of our workflow in its current
state won’t be quite as we expected. Although we’re collecting data
from engineering and marketing, we’re not actually attaching that data
to our product, it’s stored in the custom tasks only. To fix this problem and achieve the desired result, we need to add a few more actions.
Moving the mouse to the end of the list of workflow
steps will show an orange cursor. Click the cursor to open a text box
that can be used to search for the action that we want to add next.
(This cursor appears between each workflow action and before the first
action, so we can add actions wherever we need them.)
Type Set f
and then press the enter key to insert a Set Field in Current Item
action. Configure the field as Technical Details and then click the value hyperlink. Click the fx button to display the Lookup dialog.
You’ll
remember that the data entered in our custom task forms is stored in
the task. Using the Lookup dialog, we can extract this data using the
ID of the task in which we’re interested. Set the data source to Tasks.
When a workflow is associated with a list, one of the mandatory
parameters is the name of a task list to be used by the workflow for
creating tasks. This task list can be referenced using the Tasks data
source.
In
the Field From Source drop-down, select Technical Data. The column
contains the details that a user enters in the custom Collect Technical
Details form.
Since the data source to which
we’re binding contains potentially more than one item, we need to
filter it to return only the specific task in which we’re interested.
In
the Find the List Item section, set the Field to ID and then click the
fx button to show the Lookup dialog. In that dialog, set the Data
Source to Workflow Variables and Parameters and the Field From Source
to Variable: TechnicalDetailsTaskId. Since we intend to use this to
look up an item, set the Return Field As to Item Id, as illustrated:

We’ve
added this action at the end of the workflow when really it makes more
sense to attach this data before sending the product record for
approval. To move the action up, highlight it and then click the Move
Up button on the Workflow ribbon.
Add
a new Set Field in Current Item action directly underneath the action.
Use the Lookup dialog to attach our Product Image data.
Click Save to commit these configuration changes.
We’ve now completed our first workflow using SharePoint Designer and Visio. The finished workflow should look as shown:
