Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 7/20)

Step 7/20.Using association and initialization forms

Download the code

Scenario:

What we want to illustrate here is the initialization form; the current user has a manager defined in the Managers table, therefore most of the time the workflow must be able to retrieve the manager; but in some situations the manager could be in vacation ->the user needs  to specify a temporary manager;  we can achieve this by defining an initialization form which is a form that will show up when the user will actually start the workflow.

Hands-On

We’ll start from step5 solution.

Let’s design a new blank Infopath form template:

 

Name the field Account and rename the Data Source group to TemporyManager (right click on the data source- properties).

 

Add a new submit data source (Design tasksDataSourceManage Data Connections-Add-Create a New Connection to Submit Data-To the Hosting Environment…); name it Submit.

Add a button, name it Submit and link it to the following actions:

·         Submit data using a data connection (select the Submit data connection)

·         Close the form

Set the security of the form to Domain and make sure the form can be opened in the browser.

Publish the template to the network and name it InitManager.xsn. Copy it later to your project folder.

Build the project, uncomment the following lines in the install.bat file, save and call  install.bat.

::Note: Uncomment these lines if you’ve modified your deployment xml files or IP forms
stsadm -o deactivatefeature -filename U2U.ExpenseReport\feature.xml -url http://wss.u2ucourse.com/sites/sergeworkflows/
stsadm -o uninstallfeature -filename U2U.ExpenseReport\feature.xml

Create a new workflow association and test the workflow; when you start it, the Initialization form should show up :

 

We need to retrieve the manager user account (later on we’ll use a more specialized control, but in the meantime keep the textbox .

One way is to generate a class based on the class schema that will be used to deserialize the xml information stored in the InfoPath form : the .Net sdk tool xsd.exe provides such possibility.

Start the Visual Studio 2005 Command prompt (Visual Studio Tools menu):

Open the Infopath form in design mode, select the save as source File option in the file menu and save it in a subfolder (e.g initformsources). The following files will be generated :

 

We need to run xsd.exe on the .xsd file :

At the VStudio 2005 console, type :

A new file (myschema.cs)  will be generated;  add to it to your project and rename it to TemporyManagerInitForm (make sure the class is still TemporyManager) as well as the class inside  .Let’s retrieve the form informations  in the onWorkflowActivated1 event handler:

XmlSerializer serializer = new XmlSerializer(typeof(TemporyManager));
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(WorkflowProperties.InitiationData));
TemporyManager tempManager = (TemporyManager)serializer.Deserialize(reader);
this.Manager = tempManager.Account;

 

Lets modify our workflow design to use the provided manager or to retrieve it from the list.
If the manager is provided in the form, we will use it, otherwise we will retrieve it from the list.
Drag & drop and IfElse activity, move the retrieveManager activity to the left branch  and rename it as follows:

Set the ifUsualManager condition as a Code Condtion:

 

Here is the Conditional function code :

 

private void ifManagerNotProvided(object sender, ConditionalEventArgs e)
{
       e.Result = this.Manager.Trim() == string.Empty;
}

 

Build your solution, call install.bat and test the workflow.

Using the Contact selector control to select the Temporary Manager

1°Install the Contact Selector control:

Open the InitManager Infopath form in design mode; go to the design task and click on Controls;Select Add or Remove  Custom Controls; click on Add, select ActiveX Control; click on next and select ContactSelector:

 

Click next and select Don’t include a .cab file; For Binding Property select Value and click Next; from the Field or group type box choose Field or group (any data type) and click Finish:

 

2°Create the data structure for the Contact Selector Control

The Contact Selector control needs to have a specific data structure to work

Spelling and capitalization must be exactly the same, starting with the “Person” group!

 

·         Add a non-Repeating Group named: gpContactSelector

·         Add a Repeating Group named: Person

·         Add the following 3 text fields to the Person group: DisplayName, AccountId and AccountType :

 

Drag and drop the TemporyManager group to the form and design the form like this:

 

Save the form as sources, publish, copy the published template to the project folder and re-generate the class with xsd.exe as we previously did.

The code to retrieve the manager in onWorkflowActivated1 event handler should look like this :

 
XmlSerializer serializer = new XmlSerializer(typeof(TemporyManager));
XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(WorkflowProperties.InitiationData));
TemporyManager tempManager = (TemporyManager)serializer.Deserialize(reader);
               
if (tempManager.gpContactSelector.Length > 0)
        this.Manager = tempManager.gpContactSelector[0].AccountId;

Rebuild the solution , call install.bat and test the workflow with and without a temporary manager.

 

The association form is very similar to the Initialization form: it will show up when the workflow association is being made.The firm template should be inserted in the Association_FormURN child element of the <MetaData> element (in workflow.xml)

< Association_FormURN><insert association form  templateId here></ Association_FormURN>

 


This hands-on training is the property of Redwood S.L sprl and may not be organized in class or in group without the prior written permission of Serge Luca. Should you wish to organize this hands-on training in your company or institution, please contact Serge Luca  first to enter into a licence agreement. Each trainer or teacher using this hands-on training should have a licence agreement. Please ask your trainer or Serge Luca whether he or she has entered into a licence agreement with Redwood S.L sprl.

The hyperlink to this hands-on training may be placed on your website for free, on the condition that the name Serge Luca is clearly mentioned in the reference. Please send us a mail containing the link to the web page our reference is used on.


2 responses to “Step by Step Tutorial. Creating Workflows for Windows Sharepoint Services and MOSS2007 (part 7/20)

  1.  I think you forgot to mention that the initialization form must be specified in the workflow.xml file, in both the <workflow> element, as the InstantiationUrl and the <MetaData> element as the <InstantiationFormURN>.
     
    Great tutorial otherwise! Keep it up!

  2. indeed very made this blog..thanks for these instructions that you have put to disposition for all peoplehave a nice day

Leave a comment