Friday, July 27, 2012

SP Workflows


wonderfull blog abt WF

http://sergeluca.wordpress.com/2011/02/13/step-by-step-tutorial-creating-workflows-for-sharepoint-2010-retrieving-list-items-step-215/
 
Pluggable WF :
http://sandhoo.wordpress.com/2010/05/26/sharepoint-2010-pluggable-workflow-services-with-correlation-and-external-callbacks/

SP2010 improvements in WF :
http://msdn.microsoft.com/en-us/magazine/ee335710.aspx

Windows WF tutorial :
http://msdn.microsoft.com/en-us/library/dd692929

A sequential workflow moves to the next activity when it is finished executing the previous activity.
A state machine workflow typically moves to a different state when an external action occurs. This external action can be the host application raising an event handled by the workflow. The action can also be the host application pro grammatically setting the next state. You can also use the SetState activity in the workflow to move to a new state.

New in SP 2010 :

SharePoint Designer 2010 includes a new task process designer. that creates an activity in the workflow but allows flexibility in how you manage the approval process all within that one activity. This includes defining escalation processes, delegation, defining approval requirements and semantics of what happens if the underlying document is changed during the approval.
  • Site WF
  • List WF
  • Reusable Declarative  workflow : The workflow design can be reused and associated with multiple lists. Also, the Save as Template command can be usedto create a WSP file containing a reusable workflow which can be moved to another SharePoint server or to Visual Studio2010
  • High Privilege Workflows :In SharePoint 2007, workflows ran as the identity of the logged on user. In SharePoint 2010, with high privilege workflows you can specify an account to run a workflow as to give it additional needed permissions (see Figure 3). When creating a workflow in SharePoint Designer 2010, individual steps can be added that enable it to run as the author of the workflow instead of the logged on user.
  • Workflow Messaging Improvements    SharePoint 2010 adds four new workflow Event Receivers for list based workflows. The four workflow event receivers available are Starting, Started, Postponed and Completed .These are similar to other SharePoint event receivers and they execute code on the server in response to the even.These  events canb be associated with list only.The new events attach to a specific list.
  • Pluggable workflow services :   are defined by creating an interface containing methods and events. This interface is connected to a pair of activities called CallExternalMethod and HandleExternalEvent..Using these new activities, you can send asynchronous messages to an external system right from within the SharePoint  workflow
Correlation Tokens
If you’ve ever created a workflow in SharePoint, then you’ve used correlation tokens with almost every SharePoint related activity, such as CreateTask. So why is correlation needed in your custom local communication service definition? Basically it is a mechanism that allows the workflow runtime to route inbound messages to the correct instance of the persisted activities.if you have more than one activity that is waiting for external communication events. If you are writing a pluggable workflow service and have multiple HandleExternalEvent activities of the same interface type and operation, then you need to provide correlation token capabilities. If you don’t have more than one activity instance in the same workflow persisted and waiting on a particular event, then you don’t have to worry about correlation tokens 

Steps for Sequential WF :
Seq  WF
Step 1 - Create a new SharePoint Sequential Workflow project








The first activity (step) of a (Visual Studio) Sharepoint workflow must be an OnWorkflowActivated activity.

The Sharepoint team also provided more specific Sharepoint activities : you will find them in Microsoft.Sharepoint.WorkflowActions assembly; this assembly can be found in the 14\ISAPI folder and is referenced by default in our Visual Studio 2010 project (figure 19).
These activities can be dragged & drop to the Visual Studio Workflow designer surface from the toolbox (select the panel Sharepoint Workflow):




Step 2 – Add an initiation form to the workflow
Select the Workflow Initiation Form template and the new form is automatically associated with the workflow. It is an ASPX form that you edit in HTML (see Figure 11).
Step 3 – Add a workflow log activity
Step 4 – Add a CreateTask activity
 Here  :: A correlation token is used for message correlation in workflow. It provides a unique identifier that enables a mapping between a task object in a specific workflow instance and the workflow runtime in SharePoint. This is used so that when SharePoint receives a message for the workflow instance it can locate the correct task within the correct workflow instance. The CorrelationToken property must be configured and it’s not recommended to use the WorkflowToken for tasks, although this isn’t prevented in the tool. Enter the new name for the correlation token as TaskToken and press enter. Then expand the (+) symbol which appears and click the drop down to the right of OwnerActivityName and choose the workflow.
Step 5 – Add the OnTaskChanged and CompleteTask activities
    Use the While activity to wait for multiple changes to the task until you see the changes you want. The While activity must contain another activity, such as the OnTaskChanged activity. The Listen activity can also be used to listen for multiple events at one time by adding a Listen activity with actual event receiver activities inside the Listen branches. Alternatively, you can just wait until the task is deleted with the OnTaskDeleted activity.  A common requirement is to escalate or timeout waiting for an event. This is done by using a Listen activity to listen for both the task changed message and a timer message by using a Delay activity. The first message to be received by either contained activity resumes the workflow and the other activity stops waiting. The Delay activity is sent a message when the timeout occurs
    There are lots of options described above but the simplest is to use OnTaskChanged which will wait for any change to the task item and then continue on. To configure the OnTaskChanged, you need to wire up the CorrelationToken and the TaskId properties to the same fields as the CreateTask.
Step 6 – Deploy and Test the Workflow


Steps for Pluggable WF Service :

Step 1 – Create a Pluggable Workflow Service
Step 2 – Update the web.config
Step 3 – Create the workflow model
Step 4 – Run the workflow