Visit our SharePoint Forum

SharePoint developer? Submit Yourself as Freelancer

Saturday, March 1, 2008

State Machine Workflow - Preparing Association & Initiation Forms

There are two types of workflow Sequential and State Machine, to know more see :Types of Workflows

In this example I will make a Simple State Machine Workflow with Three Infopath forms and Three states. This workflow will take the name of the Approver in Association form,and then When invoked on a Item,displays a Initiation form to add Comments with the item and will create a Task for the Approver/Manager defined in Association form for Approval. If Approver Approve's the task then the workflow is said to be complete or else will be in InProgress.

Contents :
We have Three States in this State machine Workflow.
1) Start State
2) Manager Review State
3) Final State.
And Three Infopath Forms Which are:
1) Association form - For getting the name of Approver.
2) Initilazion form - For adding Comments To the item
3) Task(Review) form - To display for Approval.

Now Lets Get Started, We will first Create an Association, Intitiation and Task Review Form in Infopath 2007.
1. Create an Infopath Form,click Design a form and then Choose a Blank Form.
Imp: Make sure that the form is Browser Enabled, i.e the little checkbox displayed below the blank form is checked.
2. Now Design the form with a One table Layout and Name it Association form(You can name it something meaningfull).
3. Now Lets create the DataSource. Firstly double click on myfields and Rename as Main.
4. Add Two Fields Approve and Comments as Text to the Main datasource and drag the Approve field to the form. Create a button “Ok” as below(image).Your Infopath Form looks like this:

5. Now, you must be thinking why Comments field is added to this form? The Answer is, In Order to use the Association and Initiation form data (Approver name and Comments) we need to use schema files for these two forms in our workflow and get data using AssociationData and InitiationData Properties of Workflow.
But the golden rule is:

If you are a creating a workflow and specifying different InfoPath forms for the Initiation Form and Association Form, your forms must contain the same XML schema.

So, To do this we added a Comments field here in this form, just to make an Entry for it in Association form Schema.
We will Create a Class file from this Association fom Schema and will add it into our Workflow.

6. Now double click on OK button and Add a rule for it. Then Add Action. In the action dialog, select Submit using a data connection from the dropdown list.Click Add and on the next screen, choose to create a new connection to submit data.

7. Configure your new connection to submit data to the hosting environment. Give your new data connection a name and click Finish. Click OK two times to return to the definition of the rule.Again Click the Add Action button again and choose the Close the form option from the action dropdown. Click OK/Apply an return to the form.

8. Ok now change the security and trust permissions form options under Tools menu to Domain level and save the form.
9. Now Publish the form to a network location click next. Give a folder name to publish, and click next , now remove the path in box on this page, click OK and Next and the Finish & Close.
10. Now To create a Class file from association form Schema right click File menu, and chose Save as source.
11. Choose a folder Source(make new folder) and then ok.
12. Now we will create a class file to be used in workflow.
13. Open the Visual studio Command prompt, and move to the path of Source folder.
14. Now write the command xsd myschema.cs /c to generate class file from association form schema.
Finally! You are done with Association form.

Lets Create an Initiation form now.

Repeat the first three steps above and then create a single field under Main as Comments.
Drag it on to the form. Create a Submit button from controls and repeate step from 6 to 9.
Note that we will not create a class file here, because entry for comments field is already in Association class file.

So your Initiation form will look like this:

Last form is the Taks Form/Review Form.
Create a form with title “Manager review”.
Now create a dtasource and add a Yes/No filed. This is a checkbox to tell the document is approved. Name the field as Approve.
Create a button ok and repeate stepts 6 to 9 to create a rule for button and finally Save and Publish the form.

We are ready with the Infopath forms Now.
Lets Go the Visual Studio


Anonymous said...

Nice example, but how can you do it without infopath?

Sreenivas said...

where is the visual studio part

SharePoint Programming