Wednesday, June 30, 2010

Workflows

Workflows
Workflow: The process that defines and controls the completion of one or more tasks in order to bring about the realization of an identified goal.
Types of Workflow:
  • Workflows fall into one of two broad types, based on how the tasks are processed:
  • Sequential workflows:
    • Typically depicted as a flowchart, in which the process has a beginning, a prescribed path (which could include parallel branches, criteria-based branching, and loops, but is nonetheless a defined path) and an end.
    • Out-of-the-box workflows and workflows created in the designer are sequential workflows.
    • A sequential workflow works very well in many scenarios you are likely to encounter when implementing Workflow in Office 2007:
        • Approval
        • Translation
        • Feedback
        • Collaboration
        • Most of these scenarios, however, can be generalized into a single category known as Basic Routing, in which documents need to be moved from one person to another.
  • State machine workflows:
    • State machines are are, however, much better at modeling complex human activities.
    • Essentially, a state machine is based on the concept of conditions and transitions. A condition is a set of circumstances that indicate the current status or situation of the process being modeled.
    • Events occur and cause a transition from one condition to another.
    • Unlike sequential workflows, there is no prescribed path through the workflow.
    • Instead, the path taken by the workflow is determined by the events that occur as the workflow is processing.
    • Only two elements make up a state machine:
        • States: A condition that represents the current status of your workflow
        • Events: Responsible for managing the movement of your workflow from one state to another
    • Below figure shows a basic document approval process as a state machine. Not counting the begin and end states, which are really just labels for the diagram and will not actually be developed as part of our workflow, there are three states:
        • DocumentSubmitted: A document is in this state from the moment the workflow is initiated until the moment someone approves or rejects the document.
        • DocumentRejected: A document is in this state when the reviewer has rejected it.
        • DocumentApproved: A document is in this state once someone has approved it.
    • There are three events:
        • OnDocumentSubmitted: This event occurs when the workflow is initiated. The handler for this event will need to determine who needs to approve the document and notify them in some way that there is a document awaiting their review.
        • OnDocumentRejected: This event occurs when the reviewer rejects the document. The handler for this event will need to notify the author that their document was not approved.
        • OnDocumentApproved: This event occurs when a user approves the document. The event handler for this event will need to perform any finalization tasks for the workflow.
Windows Workflow Foundation Architecture
  • The workflow engine part of WF is responsible for providing several core services to all workflows built utilizing Windows Workflow Foundation. These services are classified into several categories.
  • Host Interface :
      • One thing that it is important to understand about WF is that it is not directly executable.
      • It is designed only to exist within another process. That other process is called the host.
      • A host is an executable process that serves as the interface between the workflow engine and workflow participants.
      • The host provides common mechanisms for all WF workflows to provide core services.
      • WF by itself is simply a set of objects that expose functionality. It does not expose a user interface (UI) that would allow you to create a workflow, manage a workflow, or respond to workflow events or notifications.
      • That is all the job of a workflow host. The host presents the interface and the functionality that allows
        • Document owners to select and assign a workflow to a document
        • Administrators to manage and track workflows
        • End users to receive notifications of workflow events that concern them
        • End users to update the status of tasks assigned to them
      • Important tasks of a workflow host include
        • Security:
            • WF is a generic engine.
            • There is no way that the developers at Microsoft could write a security model into a workflow engine that would suit every application’s needs.
            • This is left to the host to implement as it needs to.
        • User interface:
            • Similar to security, building one all-encompassing UI into the WF engine would be a nearly impossible task.
            • It would mean that the UI would need to be so generic as to be almost useless, or else that the process of customizing the UI be so open-ended and flexible that it would be exceedingly difficult to work with.
      • Activity: An activity is a discrete unit of functionality used to build a workflow.
  • Runtime Services
      • This layer provides the core services that allow individual workflows to execute. It includes these services:
        • Scheduling: The Scheduling service is responsible for controlling the runtime execution of activities. It determines when each activity runs.
        • Activity Management: This service provides the functionality for execution of activities— event management, exception management, transaction management, tracking, and persistence. As necessary, this service interfaces with the host interface layer services.
        • Rule Management: WF provides for the external application of policy to a workflow via a rules engine.
  • Programming Interface :
      • As workflow developers, this is the functionality that interests us the most; it allows us to write our own custom activities that do what we need.
      • This is the primary means of developing a highly custom workflow.

Workflow Features in WSS and MOSS
  • Content Types
      • A content type in the next version of SharePoint is a means of packaging functionality and metadata into a single manageable and deployable unit.
      • Content types are focused on the developer’s mantra of write-once, use-often.
      • Because we define the functionality, features, and information in one place, it can be managed centrally. That’s the write-once part.
      • The useoften comes in when you deploy the content type and associate it with multiple lists.
      • Each list gets the full power of the content type without having to define it over and over again.
      • Changes made to the single central copy can be immediately reflected in the lists that use it.
      • The following are kept in the content type
        • Metadata: Each content type can contain any number of columns of any data type available in SharePoint. By adding the content type to the list, you can automatically add the columns.
        • Policy: Each content type can have its own information management policy defined and enforced.
        • Workflow: Content types can carry with them their own workflows to enforce business policies specific to the content type. This is obviously the part that interests us the most.
        • Document Information Panel: Each content type can define a custom form to be displayed in the Business Bar within the Office client applications. This form can be used to keep users informed or to collect information from them.
      • Features :
        • While customizing a site definition in SharePoint 2003 was possible, it wasn’t exactly the easiest thing in the world.
        • Even seasoned veterans would not look forward to opening ONET.xml or Schema.xml and wading through line after line of raw XML.
        • In SharePoint 2007 this task is considerably less onerous because site definitions are now broken apart into Features.
        • A Feature is essentially a package of functionality that can be developed, deployed, managed, and activated as a unit. Once deployed to a server, Features can be turned on or off for individual sites.
      • There are really only five user types that come into play in a workflow:
        • Initiator: This is the person who originates or kicks off a workflow.
            • Typically, this will be owner or author of the document or list item but it doesn’t have to be.
            • Anyone with sufficient privileges can start a workflow on an item.
        • Participant: This person receives the tasks of a workflow and completes them.
        • Server administrator: The server administrator is responsible for establishing and maintaining the environment in which the workflows operate.
            • Primarily this means installing workflows on the server so that they are available to individual sites.
        • Site administrator: The site administrator is responsible for associating our workflow with a specific list or document library.
            • Often, this will be the same person as the server administrator, though it does not have to be.
        • Builder: This role is tasked with creating new workflows.
            • This role could alternately be named designer to cover the declarative workflows created with the SharePoint Designer.
      • Payload: The document or other piece of content that a workflow is assigned to. For example, in an instance of an approval workflow, the document that a reviewer must approve or reject is called the payload.
      • Windows Workflow Foundation provides a pluggable architecture to facilitate specific implementations of the following services within each workflow host:
        • Persistence: Management of long-running processes
        • Communications: Integration of myriad disparate components through a common communication subsystem
        • Tracking: Monitoring workflow progress in real time (unfortunately, this is not supported in SharePoint)
        • Transaction support: The ability to commit or roll back workflow actions as a unit
        • Timer: Support for delay or time-triggered processing
The top-10 scenarios best suited to Workflow in Office 2007:
  1. Document lifecycle: Controlling a document from creation to archiving to destruction.
  2. Document translation: In our increasingly global economy, support for multiple languages is a business necessity.
  3. Feedback: Submitting an idea (list item or document) for review and formal or informal suggestions for improvement (as opposed to approval).
  4. Collaboration: Working with a team to build a document collectively.
  5. Design approval: Whether for a web page, a brochure, a logo, or some other type of marketing material, aesthetic reviews and feedback are an integral part of this creative process.
  6. Form processing: Forms strongly imply a process. Any electronic form that generates a discrete document can likely be routed and processed by a workflow. Though certainly not limited to these types, here are a few examples of forms that would lend themselves well to Workflow: • Requisition forms • Expense reports • Travel requests • Timesheets
  7. Web content management: Moving content from concept to publication is often a precise and intense process requiring multiple levels of review and approval. Often, in highly regulated environments, there are prescribed steps to follow prior to publication.
  8. Knowledge management: Maintaining a knowledgebase is an increasingly important part of corporate life. The ability to have multiple people submit content is often one way to improve the relevancy and quantity of information available. However, without a process to manage those submissions, the knowledgebase will quickly become overgrown and unwieldy.
  9. Document approval: Not quite as formal or involved as a whole document lifecycle process, this is just a simple review and approval.
  10. : I’d like to say I was being considerate of my audience and letting them supply an entry to this “Top-10” list that met their needs, but the truth of the matter is that I got stumped at 9. Somehow, though, a “Top-9” list just doesn’t sound right. So go ahead and supply your own entry for number 10.

The Out-of-the-Box Workflows
  1. Three-State : Available in WSS, MOSS. Its Used to track and move list items through a series of states. Can be configured to react differently at various stages.
  2. Approval : Available in MOSS . It Routes a document for approval. Approvers can approve or reject the document, reassign the approval task, or request changes to the document.
  3. Collect Feedback : Available in MOSS . Routes a document for review. Reviewers can provide feedback, which is compiled and sent to the document owner when the workflow has completed.
  4. Collect Signatures : Available in MOSS . Gathers signatures needed to complete an Office document.
  5. Disposition Approval : Available in MOSS . Manages document expiration and retention by allowing participants to decide whether to retain or delete expired documents.

USING THE SHAREPOINT DESIGNER
Default Conditions Available in the SharePoint Designer

  1. Compare :  Field Allows you to specify a value for a column in the list this workflow is attached to. If the payload item has that value in the specified column, then this step will process.
  2. Compare Any Data Source : Allows you to specify a set of values to be compared. Each value can contain either a hard-coded value or a lookup to another list on the site.
  3. Title Field Contains Keyword : Allows you to specify a value to look for in the Title column. If the current list item has that value in the title, then this step will process.
  4. Modified in a Specific Date Span : Allows you to specify begin and end dates for when the list item was modified. If the current list item was modified within this span, then this step will process.
  5. Modified by a Specific Person : Allows you to specify the name of a person. If that person modified the list item, this step will execute.
  6. Created in a Specific Date Span : Same as Modified in a Specific Date Span but works off the list item creation date.
  7. Created by a Specific Person : Same as Modified by a Specific Person but works off the original list item creator, not the last modifier.
  8. The File Type Is a Specific Type : Allows you to specify a certain type of file. If the file payload matches this file extension, the step will process.
  9. The File Size in a Specific Range of Kilobytes : Allows you to specify a range of kilobytes. If the file payload falls within this range, the step will process.

Actions :
  • An action is what happens in a workflow step. If the condition(s) for a step are evaluated and indicate that the step should process, then the actions set for that step are the tasks that will be executed.
  • Actions can be either serial (each action happens after the preceding action has completed) or parallel (all actions happen simultaneously).
  • Serial actions are the default and are useful when actions must follow a process and are dependent on the completion of a preceding action.
  • Parallel actions are useful for notifications or when there is no dependency between actions.
  • To switch between serial and parallel, click the drop-down arrow located at the right side of the condition branch and select either Run All Actions in Sequence or Run All Actions in Parallel.

Default Actions
  1. Add Time to Date : Allows you to work with date values and store the result in a variable. You can add (or subtract, by indicating a negative value) time (minutes, hours, days, months, or years) to a specified date and store the result in either an existing variable or in a new variable created in this step.
  2. Assign a Form to a Group : Launches a custom wizard that allows you to easily build a form to collect information from users. The wizard is similar to the Variables Editor discussed in a moment. You can indicate which users are assigned the survey as part of the configuration for this action.
  3. Assign a To-Do Item : Launches a dialog box that allows you to specify the parameters for creating a simple task for a specified user.
  4. Build Dynamic String : Configure this step to create a string value and assign it to a variable. The string value can contain values retrieved from the current workflow instance by using lookups. The variable used to store the string value can be either preexisting or created as part of this action.
  5. Check In Item : Checks in an item so other users can edit it. You can specify Current Item or provide a column name and value to identify which item to check in. Also allows you to specify a check-in comment, which can be either hard-coded or set via a workflow lookup.
  6. Check Out Item : Checks out an item so other users cannot edit it. You can specify Current Item or provide a column name and value to identify which item to check out.
  7. Collect Data from a User : Creates and assigns a task to the specified user. Tasks are used to collect specific information from the assigned user or to have the user complete a process. The ID of the task is stored in a variable so that the information from that task is available later in the workflow via a workflow lookup. Configuring this action will launch the custom task wizard, which is similar to the Variables Editor . This action is similar to the Assign a To-Do Item action, but allows you to collect information for later use instead of just creating a task.
  8. Copy List Item : Creates an exact duplicate of an existing list item in a different list on the current site. You specify both the source and destination lists. You can specify Current Item or provide a column name and value to identify which item to copy.
  9. Create List Item : Creates a new list item in any list on the current site. You specify the list as well as values for all necessary columns. Values can either be hard-coded or based on a workflow lookup.
  10. Delete Item : Deletes an item from a list on the current site. You can specify Current Item or provide a column name and value to identify which item to delete.
  11. Discard Check Out Item : Pretty self-explanatory, but this allows you to undo the checkout of an item. All changes to that item will be lost.
  12. Do Calculation : Performs a simple calculation (plus, minus, multiply, divide, modulo) with two values, which you can either specify or base on a workflow lookup. The results of the calculation are stored in a variable. Typically, this variable would be one created specifically for this workflow.
  13. Log to History List : Allows you to write an entry to the designated history list for this workflow instance. You can use either fixed text or a workflow lookup value (but not both) as the text to be written.
  14. Pause for Duration : Allows you to specify that the workflow should suspend processing for a time period you specify (in days, hours, and minutes) when you configure this action.
  15. Pause Until Date : Similar to the previous action, except that you configure a specific date on which to continue processing the workflow.
  16. Send an Email : Sends an email when it is executed. The action can be customized to specify the recipient, CC, subject, and body of the message. Each of these fields can be either hard-coded or based on formulas, lookups, or workflow variables.
  17. Set Content Approval Status : Allows you to specify the current status of the payload item. You can also specify comments, but keep in mind that those comments will be the same for every instance of this workflow unless you use lookups.
  18. Set Field in Current Item : Allows you to set the value of a specific column in the payload item to a specified value. You can specify this value with either fixed text or a workflow lookup value (but not both).
  19. Set Time Portion of Date/Time Field : Similar to the Add Time to Date action, except that you specify a specific value for hours and minutes (i.e., not a relative time—plus 5 minutes from when the action executes) and store the results in a variable.
  20. Set Workflow Variable : Sets a variable for this workflow to a specified value. The value can be either hard-coded or set via a workflow lookup. You can reference a previously created variable or create a new one.
  21. Stop Workflow : Causes the workflow to stop processing. You can specify text to be logged to the history list with either fixed text or a lookup.
  22. Update List Item : Updates one or more existing columns in one or more lists. You can specify the list(s), the column(s), and the value(s). You can also specify Current Item to indicate the item that triggered the current workflow instance.
  23. Wait for Field Change in Current Item : Pauses the workflow until the specified column for this item from the attached SharePoint list equals the value specified. The value can be hard-coded or based on a workflow lookup.
Variables
  • Workflow variables are no different from other programming variables—they store a value (or values) for later use.
  • They can be set by the workflow originator when they initiate a workflow, set as part of a task assignment during a workflow step, or set programmatically by the workflow itself.
  • They are useful for collecting and storing values for use later in the workflow.
  • The Workflow Designer provides a number of data types to customize the data collected:
      • Boolean
      • Date/Time
      • List Item ID
      • Number
      • String
Workflow Lookups
  • A lookup is useful to refer to or retrieve another value.
  • This value could be from another list on the site where users store content or a value retrieved from the payload for the current workflow instance.
  • The Source drop-down lets you select the item you want to retrieve a value from. Lookup values can be retrieved from one of three places:
      • Current Item gives you access to item that the workflow is currently acting upon.
      • Workflow Data gives you access to the variables that have been set up as part of this workflow.
      • Select another list on the site to get access to items from another list.
  • Regardless of what is selected for the Source drop-down, you then need to specify the field or variable that you want to retrieve a value from.
  • The Field drop-down contains all of the possible choices from the selected source.
  • If you selected Current Item or another list, the Field drop-down will contain the available columns. If you selected Workflow Data as the source, then the Field drop-down will contain the available variables.
  • If you select another list as the source, you need to specify the particular item from the selected list that you want to retrieve a value from.
Check Your Workflow
  • The Check Workflow button at the bottom of the Workflow Designer window does just that—it checks your workflow for errors. When you click on it, a message box pops up that says “The Workflow contains no errors”—at least, that’s what you want to see.
  • If your workflow does in fact contain errors, they will be indicated in one of two ways:
      • In the Workflow Steps pane on the right side of the screen, the step(s) that contain errors will have an indicator next to the step name.
      • The particular condition or action will be highlighted with asterisks.
Information Types
  • Workflows in SharePoint Designer support the use of a number of different types of information in a number of different places.
      • Single Line of Text
      • Multiple Lines of Text
      • Number
      • Currency
      • User
      • Hyperlink or Picture
      • Calculated

Designing SharePoint Designer Workflows
  1. Open the SharePoint Designer.
  2. Open your SharePoint site by clicking File Open Site and typing in the URL for your SharePoint site (without the page name)—for example, http://yourserver:636/sites/marketing.
  3. Once the site has loaded, launch the Workflow Designer. From the top menu, click File New Workflow.
  4. The Workflow Designer will load and you will see the Define Your New Workflow screen,
  5. We have the following to initiate the workflow.
    • Name : Name of the workflow. It should be Unique.
    • What SharePoint List Should This Workflow Be Attached To? : This is the list in our SharePoint site which triggers the present workflow.
    • Allow This Workflow to Be Manually Started for an Item : Indicates whether or not originators will have the option to initiate this workflow from the Start a New Workflow screen.
    • Automatically Start This Workflow When a New Item Is Created :Indicates whether this workflow should be automatically initiated whenever a new item is added to the attached list.
    • Automatically Start This Workflow Whenever an Item Is Changed :Indicates whether this workflow should be automatically initiated whenever an item in the attached list is modified.
  1. When we click on the Next > button, we are taken to the core screen of the wizard. Here, we are able to define the steps that our workflow progresses through.
    • We can add as many steps to our workflow as we wish. For each step, we can add a number of conditions and actions:
    • Conditions are the triggers for the rules, such as if the list has been updated by a specific person or user group (e.g. a new member of staff that we are supervising) or that contains a keyword (e.g. "red").
    • These conditions can be set to run together with the and text selected or independently with the or text selected.
    • Actions are the events that happen when the conditions are met. The most common action is for an email to be sent.
    • Click the small arrow at the top-right corner of the Condition/Action box and select Run All Actions in Parallel from the drop-down menu to make sure that all the actions, under a particular conditional branch, are executed in parallel.
    • Before deploying our workflow, it would behoove us to make use of the Check Workflow button. Go ahead and click it. If you typed everything correctly, you should get a message box telling you that your workflow contains no errors. If you don’t get this, go back and check that you’ve completed each step correctly.
    • Once we have set up our steps, we click on Finish.
    • This will add a new Workflows folder to our Folder List. SharePoint creates an ASPX page within this folder that allows us to stop and start our workflow from within a browser. On my server, the address of this workflow would behttp://yourserver:636/sites/marketing/workflows/newlinks/newlinks.aspx.
    • To edit our workflow within SharePoint Designer, we would double-click on the XOML file (e.g. NewLinks.xoml) in our Folder List.
    • XOML (pronounced zommel) files are standard XAML (pronounced zammel) files that specifically contain workflow serialization information.

Sharepoint