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

 

image

 

By Serge Luca

MVP

image

 

Step 5/20. Creating and Using Infopath Tasks Forms  

Download the code

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 ToolsForms OptionSecurity and Trust) :

 

Publish the infopath form : File MenuPublish: 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.

Close Infopath.

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:

 

  ReceiverAssembly="Microsoft.Office.Workflow.Feature, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
  ReceiverClass="Microsoft.Office.Workflow.Feature.WorkflowFeatureReceiver"

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):

 

        private void ApproveRejectTask_MethodInvoking(object sender, EventArgs e)
        {
            …
            this.ApproveRejectTask.TaskProperties.TaskType = 0;
        }

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 :

 

        private void WaitForApprovalRejection_Invoked(object sender,
ExternalDataEventArgs e)
        {
            string acceptedRejectedStatus =
                this.AfterApprovRejectProps.
                ExtendedProperties["status"].ToString();
            this.WorkflowProperties.Item["Status"] = acceptedRejectedStatus;
            this.WorkflowProperties.Item.Update();
        }

 

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.


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

  1. Hi Serge
     
    This blog is really informative for integration with infopath, but U2U.ManagerActivity workflow is not explained properly
    it shows 4 activity, which are not described so i m stuck up in the middle of it.
    I am really eager to know more about this blog
    please reply me soon as i need to finish this assignment
     
    Regards
    Divya

  2. Hi Divya,
     
    I suggest that you start from step1; everything is explained from scratch; if you need more help, send me an e-mail.
     
    Regards,
     
    Serge 

  3. Hi Serge,good job with the tutorial, I\’m learning to create workflows and this one has been the most helpful. However, in this particular part, I\’m not quite clear on how did you get the 0xWhatever value for TaskListContentTypeId in workflow.xml?Thanks a lotKerray

  4. Hi Serge,
     
    After successfully publish infopath form when I started workflow and click on edit task then  I got  error \’Could not found Specified form\’ and \’The form has been closed\’. Can you let me know what kind of error this is. You help is highly appreciated.

  5. string acceptedRejectedStatus =
                    this.AfterApprovRejectProps.
                    ExtendedProperties["status"].ToString();
     
    It given me always error indiating that element "status" is null or doesn\’t exist. Hashtable with extended properties has GUID-s of fields as the keys, not a normal human-friendly names. I\’m not sure if this is the common problem or do I missed something very important here…

  6. hii….good work ya had done…
     
    i\’m facing some problem while createin form…
    is there anyway that you can teach me or send me a sample..?
     
    this is what i need to ask u..
     
    ……………………………………………………………………………………………………………………………………………………………………..
     
    example: i create a leave form…example : with 2 user (Worker, Approver)
    -Leave Form with 3 buttons ("Submit, Approve, Reject")
    Submit button will be viewable to all, as for Approve Buttons / Reject Buttons, it will be only be viewable by Approver
    then i upload it on the server, when a worker is to apply leave form that form,
    Worker wont be able to see the  Approve Buttons / Reject Buttons"Hiiden", after Worker submit it…
    When the Approver login in to Approve / Reject, he can only see the Approve Buttons / Reject Buttons….
    upon clicking the  Approve Buttons / Reject Buttons, the Columns Display will update the Status …
    is it possible to create this type of form…?
    thanks
     
    with regards
    hope to hear from you soon…
     

  7. hi serge, i have followed all the steps described here. im getting following error when submitting the approve-reject (by pressing Accept/Reject button)form.
     
    \’Form\’ is an unexpected token. The expected token is \’=\’. Line 1, position 44.

Leave a comment