By Serge Luca
Step 7/20.Using association and initialization forms
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.
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 tasks–DataSource–Manage 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.
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:
Set the ifUsualManager condition as a Code Condtion:
Here is the Conditional function code :
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 :
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.