Welcome to MSDN Blogs Sign in | Join | Help

Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Step 2: Design and Bind Your Forms

With your workflow skeleton in place, you should now be able to see where you will be collecting data and what data to collect.  With this information, you can create your forms, set up a schema for the collected data, and write the code behind your workflow to utilize that data.

Behind the Scenes of the Four Types of Workflow Forms

There are four types of workflow forms that you can implement: association, initiation, task edit, and modification.  To determine which ones you need, ask yourself the following questions:

                Association: Do I want to input default values for initiation, or values that the workflow needs that only list administrators should set?

                Initiation: Do I want people to start the workflow manually?  If so, is there information that the workflow needs to start off with?

                Tasks: Are people involved in my workflow?  Will I be assigning tasks?

                Modifications: Will the workflow need to be adjusted in-flight?

If you answer yes to these, then you’ll probably need a form. 

All your workflow forms will need to do the following things:

1)      Collect data from the user

2)      Call an object model function to perform its action (e.g. create an association, start the workflow, edit a task, etc).  This function takes the data as a parameter and passes it into the workflow.  (MOSS provides a shortcut for IP forms that we’ll talk about in a bit)

Once this function is called, the SharePoint will trigger an event in the workflow schedule and pass in data (excluding associations, which happen outside of the schedule).  Thus, the workflow schedule must have a corresponding event handler activity to respond to the event.  The data will be stored into a variable bound to a receiving property on that activity.  

For example as seen in the following diagram, to start a workflow, the initiation form calls a function called StartWorkflow, which takes the initiation data string as an argument.  StartWorkflow triggers the workflow activated event, which triggers the OnWorkflowActivated activity (Hence, OnWorkflowActivated needs to be the first activity in your workflow).  It stores the initiation data into the variable bound to the WorkflowProperties property on that activity.  The following diagram shows this process: 1) aspx page calls StartWorkflow and passes in form data, 2) SharePoint stuffs the data into an event handler activity in the workflow (OnWorkflowActivated).

And it works similarly for tasks and modifications.  Below is a chart of what functions each form type calls, which activity you need to receive the event, and which property on that activity gets stuffed with the data:

Form Type

Required Actions

Event Handler activity and Data Receiving Property

Association

(MOSS host page: CstWrkflIP.aspx)

Create SPWorkflowAssociation object (SPWorkflowAssociation::CreateListAssociation(… associationData))

Add association to list or content type (SPList.AddWorkflowAssociation(association))

None (associations exist outside of the workflow schedule)

Initiation

(IniWrkflIP.aspx)

Start a new instance of a workflow (SPWorkflowManager.StartWorkflow(association, web, list)

OnWorkflowActivated.WorkflowProperties

Stored into these SPWorkflowActivationProperty fields: InitiationData, AssociationData

Task edit

(uses form specified in OffWFCommon task content type, WrkTaskIP.aspx)

Change the task (SPWorkflowTask.AlterTask())

OnTaskChanged.AfterProperties

Modification

Modify the workflow (SPWorkflowManager.ModifyWorkflow)

OnWorkflowModified.ContextData

 

Specifying Which Forms To Use

When you have your forms, you’ll probably want to specify which form to use for what stage of the workflow, i.e. which form to use for association, initiation, etc.  This is defined in the workflow template xml file (workflow.xml), which we’ll see in the deployment step.  There is a one-to-one mapping between form and type, for example:

<Workflow

       Name=…

       TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160"

       AssociationUrl="_layouts/CstWrkflIP.aspx"

       InstantiationUrl="_layouts/IniWrkflIP.aspx"

       ModificationUrl="_layouts/ModWrkflIP.aspx"> 

In this snippet, we’re using the out-of-box IP host pages for that come with MOSS (we’ll explain what we mean by IP host pages in the next section).  In short, you would use the pages specified above if you’re using IP forms, and you’d want to specify your own aspx pages in these fields if you’re using aspx forms.

For Tasks, instead of specifying a page, you specify a content type that specifies the appropriate view and edit aspx page.  The OffWFCommon content type that comes with MOSS is for use with IP forms.

FAQ:  How to specify multiple task or modification forms
You can only specify one aspx page for each form type, and one default task content type.  However, your workflow might need more than one form for tasks and modifications.  If you are creating your own custom aspx pages and need more than one task edit form, you will need to create a content type for each type of task and use the CreateTaskWithContentType activity to create a task that uses that type (instead of the CreateTask activity).  If you need more than one modification form, either create an aspx page that redirects to multiple forms, or create a page with multiple views based on page parameters and workflow template fields.  If you are using InfoPath forms, the MOSS out-of-box aspx pages, which automatically load the appropriate IP form based on “FormURN” tags in Metadata section of the workflow template xml.

InfoPath vs. ASPX Forms

We now know what needs to happen in the forms behind the scenes, so we just need to choose the technology: InfoPath (IP) or ASPX forms.

In reality, all (browser-based) workflow forms that you see are aspx pages.  What makes InfoPath forms different is that they are hosted in an XmlFormView control in out-of-the-box aspx pages in MOSS.  These are the pages we specified in our workflow.xml snippet in the last section.

There are several advantages to using InfoPath forms that you should consider:

1)      They can be used directly in the core Office 2007 client applications. 
The client applications (Word, Excel, PowerPoint, Outlook, InfoPath), like aspx pages, can host InfoPath forms for workflow.  So when you click on that “Edit this task” button that appears in Outlook or Word, the IP task form will appear as a dialog directly in the application to maintain context.  This form is exactly the same form as you’d see in the browser, so you have a symmetric experience.  If you’re using ASPX forms, this button will redirect you to a browser.

2)      They are easy to author with InfoPath designer.
Drag and drop, IP rules wizard… if you enjoy the authoring experience in InfoPath, this is a plus.

3)      No code required
No code required?  But what about calling the functions to perform the specified action?  Well, the MOSS aspx host pages make the object model calls for you, so that all you need to focus on is designing your IP forms in the IP designer.  More specifically, these forms 1) load the IP form, 2) wait for the IP form to send its xml back to it, and 3) make the OM calls.  If the out-of-box functionality is not what you desire, you can code your own ASPX page to host the IP form and make the appropriate calls.  But remember that you might also be able to write code behind your IP form to add that functionality.

Creating InfoPath Forms

For every IP form you create for workflow, you’ll need to do the following things:

1)      Name your fields
Define your schema according to how you want to reference your data in the workflow.  So if you have a control to collect comments and call it “comments”, and in your workflow code, you’ll be able to reference the data in that field as “comments”.

2)      Add a submit button with 2 rules
We know that IP forms are hosted in an aspx page or client application, so when the user wants to submit the form, have the submit button a) create a connection to submit the xml data/string to the host environment (the host will handle the rest), then b) close the form so that it doesn’t just submit and stick around.

3)      Add domain level trust
Yeah, you need this for workflow forms.  In IP, it’s in Tools->Form Options->Security and Trust

4)      Publish to your project folder
Workflow forms will be deployed when you deploy your workflow, so keep them handy with your project so that the deployment tool picks them up and you can tweak as necessary.  Don’t forget to leave the alternate access path blank, or else it won’t install!

Pitfall: Forgetting to clear the alternate access path
It’s easy to forget to clear the alternate access path in the Publish wizard, since it’s filled in by default after you specify the publish location; be sure to actively delete the default value that they provide.

Pitfall: Confusing the IP document with an IP workflow form
A trap that people run into is thinking that a workflow IP form is the same as an IP document that is saved as an xml file (such as a forms library document).  If you are designing a workflow for a forms library, think of the library’s form template as an ordinary document, and the workflow forms as process UI.  Workflow forms are not files that are saved; they are merely UI to collect data, and the results are passed into the workflow, not a file.

A Fifth Step for Tasks: ItemMetadata.xml

If you need to load task data in your task forms without any code, you need an extra step. Unlike the other workflow objects, tasks are list items that can be tweaked in ways that the form and workflow don’t expect, for example, adding a column and hence changing the item schema.   So to compensate for the possibility of schema differences between the task data and the form, we let the developer define the fields in the task that are needed to populate the form controls, through a file called ItemMetadata.xml.

SharePoint passes the task as xml into this file, which should be a secondary data source on the form.  It’s case sensitive, and it uses the exact schema of the task.  So step 5 (do this before step 4) for task forms is:

5)      Add an ItemMetadata.xml file as a secondary data source to your form

The file contents would look something like this:

<z:row xmlns:z="#RowsetSchema"

                ows_instructions=""/>

where “instructions” is the name of a field or column on the SharePoint task itself.  You can select ows_instructions as a default value for your fields.

Binding Form Data into Your Workflow

As we saw earlier, the form pages call functions that trigger events in the workflow and stuff the form data into a property on the corresponding activity.  So all you need to do when the event is triggered is write a handler that parses the data and uses the data to perform actions in the workflow.

Initiation form data is passed into the OnWorkflowActivated activity as a string, so whether it’s via a serializable class or by xml parsing helper functions, you just need to get the string into data you can use.  Modifications also pass a string into the OnWorkflowModified activity.  Parse this similarly to Initiation form data.  Again, if you’re using IP forms, the “Submit to host” passes the form data as an xml string to the host that is then passed directly into the function call, so for initiation and modifications, follow the form schema to parse it (e.g. by using the xsd generator tool to create a class for it).

Tasks are slightly different in that when a form is submitted, data is saved directly to the task item on the list.  SharePoint does a little magic on the task and copies the task info into the workflow as an SPWorkflowTaskProperties object that contains the properties that changed on the task item itself (and null for properties that didn’t).  For IP forms, the host parses the xml and saves each field to a column on the task item with the same name. So if you have a form field named “AssignedTo”, it would write the value to the “AssignedTo” property on the item.  For a field that does not have a matching column on the list, e.g. “foo”, that field will be saved as a hidden field on the task object.  Hidden fields are exposed in the workflow as a hashtable called ExtendedProperties on an SPWorkflowTaskProperties object, and can be referenced in the workflow by using the field name as a key, e.g. afterProps.ExtendedProperties[“foo”].

Binding Object Data into Your Forms

Pre-populating data into the forms does not come from the workflow itself.  Rather, these forms get their data from SharePoint objects related to the workflow.

For example, both association and initiation forms load initial data from the SPWorkflowAssociation object on the list or content type. 

Task forms pull their data from ItemMetadata.xml, which is the SharePoint task object as xml.

Modifications pull data from the ContextData string in the SPWorkflowModification object.  Note: this object needs to be reinitialized by the workflow if the data changes.

 

Next on Developing Workflows in VS: Coding Your Workflow

Thanks!
Eilene

Published Sunday, November 26, 2006 9:00 AM by sptblog
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Why does every sample have to include InfoPath...Please provide an example that uses ASPX forms

Sunday, November 26, 2006 7:36 PM by Jason Noble

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

A couple of weeks ago, the ECM starter kit for Beta2TR was released through the ECM blog -

http://blogs.msdn.com/ecm/archive/2006/10/10/ECM-Starter-Kit-for-B2TR.aspx

Can we expect an update of these workflow templates for the RTM version or can we just start with these templates on a MOSS RTM server?

Any news on the separate Workflow developer kit for WSS - last update on MSDN was 6/29/2006 for Beta2 - I haven't seen anything new recently...

Monday, November 27, 2006 5:14 AM by Joris

# Workflowentwicklung für SharePoint

Gestern hat das SharePoint Products und Technologies Team den vierten Artikel einer Serie zur Entwicklung

Monday, November 27, 2006 2:37 PM by XML is the glue...

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi Jason ad Joris, the Collect Feedback sample is ASPX only. The RTM ECM Starter Kit will be shipped inside the MOSS SDK, the WSS workflow templates will be shipped inside the WSS SDK. These should be coming out in the next couple weeks...

Monday, November 27, 2006 9:26 PM by Eilene Hao

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Share Point services SDK says "Because the workflow association is not created until the custom association form is submitted, Windows SharePoint Services also passes the following query parameters to the custom association form i.e. WorkflowName,AllowManual,GuidAssoc etc".But I couldnot get anything else other than List (ID of the List) from query string for my association ASPX page.Am I missing some thing in workflow xml or share point by default should pass all these information in query string to custom association page?

Thursday, November 30, 2006 12:14 AM by elizageojy

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi Eliza, these are hidden, so they don't show up in the string.  But take a look at the WFAssoc.cs file in the Collect Feedback sample in the ECM Starter kit to see how to access them inside the page.

Friday, December 01, 2006 7:36 PM by Eilene Hao

# Implementare un workflow con Sharepoint

Visto che mi avete chiesto info a riguardo vi giro i link alle prime 7 lezioni: Lezione 1 Lezione...

Monday, December 04, 2006 6:35 AM by Romeo Pruno

# OnePage Workflow in SharePoint 2007

OnePage : der einfache Blick auf das Wesentliche - die wichtigsten Informationen zu einem Thema auf einer

Tuesday, December 05, 2006 2:37 PM by SharePoint, SharePoint and stuff

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi,

Is possible to pass a structure that can be repeated to the ItemMetadata.xml, or is possible to send a more complex structure?, different that this example

<z:row xmlns:z="#RowsetSchema"

               ows_instructions=""/>

Wednesday, December 06, 2006 8:18 AM by Sandro Pereira

# Creating Workflows with Visual Studio 2005 (Walkthrough)

Im not sure how many have found this yet but Eileen Hao has put together a Seven Part walkthrough with...

Thursday, December 07, 2006 12:25 PM by Bob Fox's Sharepoint Blog

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Sandro, you can pass in the xml for a repeating structure, but unfortunately, you'll have to write custom code to parse it.  The IP repeating section doesn't let you bind to it directly, and itemmetadata is flat.

Friday, December 08, 2006 8:40 PM by Eilene Hao

# What About Workflow and ASPX Forms?

Hi everyone, I’ve gotten a lot of questions about using aspx forms in workflow, so I wanted to talk about

Tuesday, December 19, 2006 3:51 PM by Microsoft SharePoint Products and Technologies Team Blog

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi Eilene,

Any update on when those SDKs will be released?

Tuesday, December 19, 2006 5:19 PM by Nick

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

OH MY GOD - this is fantatic stuff!  It's everything you need to know!

Thursday, February 15, 2007 12:05 PM by Powlo

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

How can I create two task edit form?

I am creating an Approval workflow where Reviewer can Approve or Reject or ask for More Info.

So first time when task created for Reviewer, he/she will edit the task using specific task edit form

If Reviewer reassign task back to Originator then Originiator needs to edit the task and this time the task edit form would be different.

How can I achieve that?

Thanks

Wednesday, February 21, 2007 12:39 PM by Andy

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

actually the method

site.workflowmanager.startworkflow(...)

takes 3 parameters .

i suggest that the aspx submission form (used to collect data) should fill fields of a pre created List

that starts a workflow in turn.

Thursday, March 08, 2007 9:54 AM by Mohammed

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

in order to use different task forms consider using CreateTaskWithContentType activity.

Thursday, March 08, 2007 9:56 AM by Mohammed

# Start Learning Workflows!!

Wow such an exciting topic to learn!! its nice and fun yet its a bit difficult to grasp easily,,, This

Thursday, April 12, 2007 9:46 AM by Code Eater

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi Eilene,

i am trying to pre-populate the Initiation Form (IP form) with some values. I read in your post that if i set the values in an Xml string of the same schema and assign it to the AssociationData property, then the IP form should display it right? It is not working on my end. Could you detail the steps for getting it right?

Thursday, April 26, 2007 12:39 AM by Amol

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi Eilene,

Is it possible to use modification forms with a state machine workflow?  I've been able to use them with a sequential workflow, but when I try to set them up in a state machine workflow, I never see the link to modify the workflow.

Thanks for the great series.

-Cynthia

Thursday, May 10, 2007 12:55 PM by Cynthia

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

I try to create aspx form. But it's very hard. Could you help me!

Monday, May 28, 2007 4:46 AM by Nguyen Huy Hoang

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Thanks for this very informative post. Alas, after lots of initial enthusiasm, I just hit a brick wall with the limitations of the flat propertybag in OnTaskChanged.AfterProperties.ExtendedProperties hashtable.  It would imho be a killer feature for a future version to support a) access to the full infopath xml doc in OnTaskChanged(akin to InitiationData) and b) provide an elegant way to push an updated version this xml back into infopath.  Real-world forms for proces UI are seldom flat property collections, and often contain rich, hierarchical data (i.e. repeating sections). The alternative of hacking it together using ItemMetaData & diy parsing of xml strings is not attractive, errorprone and rather a showstopper today.

Tuesday, July 10, 2007 11:48 AM by L. Olivers

# SharePoint ワークフローで状況依存なフォーム (workflow form) を表示する

環境: Office SharePoint Server (MOSS) 2007 Visual Studio 2005 Office SharePoint 2007 SDK (ECM Starter Kit)

Thursday, July 26, 2007 5:15 AM by 松崎 剛 ブログ (Tsuyoshi Matsuzaki Blog)

# SharePoint ワークフローで状況依存なフォーム (workflow form) を表示する

環境: Office SharePoint Server (MOSS) 2007 Visual Studio 2005 Office SharePoint 2007 SDK (ECM Starter Kit

Thursday, July 26, 2007 5:44 AM by Noticias externas

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hey,

I am Requesting You all, intelegent people PLease tell me how to created aspx form for workflow instead of IP forms. Please otherwise i'll go made, by meeting failer after failer

elien please do something

Wednesday, August 08, 2007 9:25 AM by Vikash

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Has anyone tried this using Forms Server instead of the InfoPath Form Services in MOSS?

Thursday, August 16, 2007 8:20 PM by whitfld64@hotmail.com

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi

Is there anywhere I can customise the email content that is generated on the out-of-the-box workflow as the link to the page to be reviewed is a relative link, not including the site

Thanks

Andy

Friday, August 31, 2007 10:34 AM by Andy

# 2007 MOSS Resource Links (Microsoft Office SharePoint Server)

2007 MOSS Resource Links (Microsoft Office SharePoint Server) Here is an assortment of various 2007 Microsoft

Wednesday, September 12, 2007 11:13 AM by The Boiler Room - Mark Kruger, Microsoft SharePoint MVP

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Hi all.

Every who need working with aspx forms within SP workflow should read WSS SDK article named  

"Workflow Task Forms".

Thursday, October 11, 2007 4:11 AM by nSP

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

How can I get the data from a Repeating Section in the workflow using AssociationData and InitiationData?

Thursday, October 18, 2007 10:53 AM by HANK

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

I have created a sequential workflow and attached Association, Initiation and Task form.

Association happens successfully but on initiating maually I get following error message:

"The workflow template has specified no FormURN for this page."

I have specified URN's in workflow.xml so this message is not clear, what does it mean?

Please can any one suggest the solution.

Saturday, October 27, 2007 6:12 AM by Vishal Varshney

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

To specify the Initiation form. Open the form in desing mode, select file->properties and copy the contents(i.e the forms URN) of the ID text box of the Form Template Properties dialogbox. Paste this into between the XML node element for the Initiation form in your workflow.xml fil.

Next place the Intiation form's name including the .xsn extension, in the Install.bat file.

Wednesday, December 05, 2007 3:08 PM by paul

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 10:21 AM by SharePoint mola

# SharePoint resources

Gracias a Mark Kruger (SharePoint MVP) por esta lista de recursos de SharePoint donde podréis encontrar

Monday, February 18, 2008 11:09 AM by SHAREPOINTBlogs.com Mirror

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Can anyone explain how to "reinitialize the ContextData object" as stated in this article:

Modifications pull data from the ContextData string in the SPWorkflowModification object.  Note: this object needs to be reinitialized by the workflow if the data changes.

For example, if the Approver is changed in the workflow fields (and in the task via an UpdateTask activity), a subsequent modification will still have the original approver in the ContextData.

Note: the SPWorkflowModification.ContextData property is Read Only, both in the onWorkflowModified_Invoked event and in the modification form itself.

Thanks!

Thursday, March 06, 2008 11:39 AM by JLT

# Thanks to Lexis Nexis!

We are about to start a great day showing technologies like .NET 3.5, Visual Studio 2008, and SharePoint

Wednesday, April 30, 2008 7:40 AM by Kirk Allen Evans's Blog

# 应用SharePoint的Workflow须记住的10句话!

1)SharePoint的工作流是基于文档的工作流,只能关联到列表,文档库和内容类型上 2)SharePoint的工作流模板利用网站功能(Feature)来发布 3)SharePoint的...

Tuesday, September 23, 2008 11:12 PM by 晃晃悠悠

# re: Developing Workflows in VS: Part 4 - Design and Bind Your Forms

I am building a Visual Studio workflow to set the title of an item if the title is "(no title")/null. I want this to be reusable across the site.

So what I would like to do is allow Administrators to associate the workflow with the list and then specify a column from that list to be used as part of the title. The title will then be a concatination of the speified coulmn plus the created date. It is much like the setting the default values to the approval workflow.

Does anyone know of any useful pages describing how to do this?

Many thanks

Alan P

Wednesday, October 01, 2008 6:29 AM by Alan P

# 微软sharepoint产品组博客——使用VS进行工作流开发系列博客

最近的两个月一直在研究SharePoint的内容,从配置到开发,从配置,到sharepoint对象模型,webpart,eventhandler,workflow,contenttype,自定义字段...

Monday, November 24, 2008 12:34 AM by virus

# 使用VS进行工作流开发系列博客5-Developing Workflows in VS: Part 4 - Design and Bind Your Forms

Monday, November 24, 2008 4:50 AM by virus

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker