Developing workflows in vs: Part 3-five steps for developing your workflow

Source: Internet
Author: User

 

Okay, the moment you 've all been waiting for: How do you write a custom SharePoint workflow? In this section, we will break it down into five steps:

1) model your workflow in Visual Studio

2) create and bind your forms

3) code your workflow

4) Deploy your workflow to the server

5) debug

(Note that these are only suggested steps; you can do this any way that fits best for you .)

Step 1: model your workflow

The first step is to model your workflow using the Visual Studio extensions for Windows Workflow Foundation designer, I. e. create a new workflow project, Drag and Drop activities into your workflow surface, and set the properties that you need. having a skeleton of your "flow" will help you see what needs to be done and where you will need to bind your form data in later steps. also, initializing the properties on your activities up front may save you some time having to switch back and forth between designer and code-behind file when you start writing your code.

FAQ: The workflow template can't open in Visual Studio
When using the SharePoint workflow vs templates, you may encounter an error opening your. csproj. this usually means that you do not have the Visual Studio extensions for Windows Workflow Foundation installed. check to see if you have anything under the "workflow" Node before you worry about the "SharePoint" node.

SharePoint activities

SharePoint comes with a set of activities. tags of them wrap the service methods mentioned in the mechanics section above, or rather, they are the service APIs in activity form.Method activitiesAreBlue, AndEvents handler activitiesAreGreen. The methods derive from the WF callexternalmethod activity (see item activities sample in the ECM starter kit), and the functions you write for the method invoking property are executed rightBeforeThe service method executes. The handlers derive from the handleexternalevent activity, and the functions you write for the invoked property are executedAfterThe service handler executes and wakes up the workflow.

Add an event handler activity whenever you want the workflow to commit the method actions or go to sleep, then wake up when an event fires.

To create and bind variables to your activity properties, use the activity Property dialog by clicking on the blue icon next to the property. if instead of clicking on the blue button, you type in a value directly, for example, typing 1 for an int property, the property will be set to that constant value. (It's less expensive for performance to do this if you know a value won't change)

Pitfall: Using createtask or ontaskchanged's spworkflowtaskproperties objects as a real time representations of the SharePoint task item
When using createtask, the object that you bind to the taskproperties property to set initial data for the task is only initial data; it's not synchronized with the task, so it will not reflect any changes to the task, or vice versa. the same concept applies to ontaskchanged's afterproperties property.

The importance of correlation tokens

A common mistake when initializing properties is not setting the correlation token correctly to map different activities to the same object. If not done correctly, the workflow will not wake up or respond to events.

Think of a correlation token as an identifier that WF uses to identify and respond to the corresponding objects in Sharepoint. for example, if you have in a sequence the activities createtask, ontaskchanged (to wait for the user to edit his task), then completetask, you want these three activities to map to the same task in SharePoint; you do this by specifying the same correlation token in all three.

You will need a token for activities that relate to the workflow itself, a token for activities related to a particle task or item, and a token for each modification. Here isGrouping of activities that need the same correlation token(Each group shoshould have its own token ):

"Workflow" token:

  • Onworkflowactivated
  • Onworkflowitemchanged
  • Ohworkflowitemdeleted
  • Setstate
  • Sendemail
  • Updatealltasks

Task token:

  • Createtask
  • Createtaskwithcontenttype
  • Updatetask
  • Deletetask
  • Completetask
  • Rollbacktask
  • Ontaskchanged
  • Ontaskdeleted
  • Ontaskcreated

Modification token:

  • Enableworkflowmodification
  • Onworkflowmodified

 

 

Missing from this table are the list item service APIs, which don't have activities around them in the box. but if you use wrapper activities for them (such as those encoded in the ECM starter kit Item Activities sample), You wocould treat them similarly to tasks: every related item activity shocould use the same correlation token.

Pitfall: Using the workflow token as the task token
Sometimes developers use the workflow token as their task token; now all tasks map to the same thing, right? This isn' t quite correct. make sure each group and object has its own token. for example, don't use the overall workflow token for your tasks. also, create a separate token for each distinct task. note: If you have a task in a sequence inside the Replicator activity, changing the "Owner activity name" to the sequence will automatically create a new token for every instance of the sequence.

 

Next on developing workflows in vs: Design and bind your forms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.