Step 5/20. Creating and Using Infopath Tasks Forms
Creating and linking the Infopath form
(start with Step 4 solution)
Let’s start Infopath 2007. Select Design a Form Template-Blank:
Check the option Enable browser-compatible features only.
Design the following form with 2 buttons :
We need to create a Data Connection; select the Design Tasks panel, select Data Sources and click on Manage Data Connections:
Add a new data connection; select Create a new connection to Submit data :
Click Next to select to the hosting environment… :
Click Next and name it Submit.
On the Design task panel click on Data Source, right click on myfields and add a new field; name it Status an keep the text data type:
Click on the Accept button, click on the Rules button and on the Add button.
We are going to add 3 actions :
· setting the status field to Accepted or Rejected,
· Submitting the data
· Closing the form
Click on the Add Action button, select the Set a field’s value Action, select the field status and set the Value to Accepted :
Follow the same procedure for the Reject button , but set the Value to Rejected.
On both the Accept and Reject button, click on the control, select Rules, select rule1, click on the Modify button: add a new action :
Add another action :
Don’t forget to follow the same procedure for the Reject button.
Set the Security Level of the form to Domain (menu Tools–Forms Option–Security and Trust) :
Publish the infopath form : File Menu–Publish: click ok to save the form and publish the form to a newtwork location:
Click Next, save the form in your project directory with the name ApproveReject.xsn.
Click on Next and keep the text box empty (very important) :
Click Next until the Wizard closes.
With Windows Explorer, go to the form, right click on it:
Select Design and go to the File menu, select Properties:
Copy the ID to to the clipboard.
Modify the manifest file (workflow.xml) in order to declare this form as the form to use to interact with the task:
In the MetaData element, create a Task0_FormURN child element :
Several forms can be used (see part 6 of this tutorial) therefore the code in the workflow will refer to the form by specifying the number provided in the Task<X> element name; for instance here <X> is 0, so in the code we will refer to the form 0.
In this part of the tutorial we are going to use only one type of task to interact with the workflow, so specify one task content type :
In the feature.xml file, add the following attributes to the feature element for handling the infopath form:
Register the Infopath form in the feature.xml file:
Modify the install.bat file in order to copy the Infopath Form :
In the same file, uncomment the lines following the Note :
::Note: Uncomment these lines if you’ve modified your deployment xml files or IP forms
In the workflow designer, double click on the ApproveRejectTask activity : in the ApproveRejectTask_methodInvoking, set the link between the Task and the TaskForm0 (which references our Infopath form):
Now, let’s retrieve the information coming from the Infopath Form : is our expense report approved or rejected ?
We can retrieve these value at the level of the workflow by using the AfterPropertries property of the OnTaskChange activity :
The type of AfterProperties is Microsoft.Sharepoint.Workflow.SPWorkflowTaskProperties.
The data coming from the Infopath form controls will be stored in its ExtendedProperties property which is an Hashtable.
Let’s bind AfterProperties to a new field (AfterApprovRejectProps) in the workflow class:
Double click on the WaitForApprovalRejection activity ,r etrieve the Infopath fields value from the HashTable (ExtendedProperties) and change the ListItem status :
Rebuild the solution, call install.bat, test the workflow; click on the new task in the task list and the Infopath Form should show up; submit your choice and check the item status.
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.