Friday, October 16, 2009

InfoPath 2007 form and Nintex workflows 2007 - Part 1

Integrating InfoPath 2007 form and Nintex workflows 2007 - Part 1 covers how InfoPath forms interact with Nintex workflow web services.

InfoPath 2007 form and Nintex workflows 2007 - Part 2 covers on how to deploy browser enabled InfoPath forms as Content Types in your SharePoint List/Library.

There are two important Nintex workflow web services which integrates InfoPath form with Nintex workflows, they are:
a. GetRunningWorkflowTasksForCurrentUser(string fileUrl)
b. ProcessTaskResponse(string comments, Outcome outcome, int spTaskId)

a. GetRunningWorkflowTasksForCurrentUser:

This webservice identifies nintex workflow task associated with the currently logged in user for a given List Item which the nintex workflow is bound.

It takes fileUrl as an input String parameter. fileUrl is the server relative url of the list item on which the nintex workflow is currently running.

This webservice helps you retrieve various data fields like SharePointTaskId, HumanWorkflowID, WorkflowName, Comments, WorkflowName, WorkflowInstanceId, TaskName, TaskType etc...

We will see the importance of the same in the Implementation Scenario section of this post.

b. ProcessTaskResponse:

As the name suggests, this web service completes the workflow tasks on behalf of the user.It does the job of completing tasks of the type: Approved, Rejected and Continue. You can imagine an Approval/Review task form. Input parameter comments accept Approvers/Reviewers multi-line comments in the form of a string, outcome is generally of the following pre-defined types either Approved or Rejected for the Approver or else Continue for the Reviewer and lastly spTaskId accepts the SharePointTaskId retrieved by querying the GetRunningWorkflowTasksForCurrentUser web service.

Implementation Scenario:

a. Design an InfoPath form: User fills an InfoPath Expense Report form as shown in Figure 1.1.

Sample Expense Report Infopath Form

Figure 1.1















































b. Submit Data Connection: The form has one Submit data connection which submits all the details of this form to a SharePoint document library, snapshots below show how to create a submit data connection in InfoPath:

i. Go to Tools -> Data Connections -> Click on the "Add " button and you will see the wizard shown below: Choose "Submit data" option and click on the "Next" button





















ii. Choose "To a document library on a SharePoint site" option and click on the "Next" button. Select to a document library option





















iii. Enter your Document library URL, File name (must be a unique file name) and Check mark "Allow overwrite if file exists" option and click on the "Next" button






























c. Receive Data Connections: The InfoPath form must compulsorily have two receive data connections that make calls to the Nintex web services namely:

GetRunningWorkflowTasksForCurrentUser and ProcessTaskResponse respectively. You may have other receive data connections in your InfoPath form, for eg: I may have another receive data connection to receive data from a SharePoint List/Library and show it as a dropdown in my InfoPath form.

Snapshots below show us how to create a Receive Data Connection of the type Web service.

i. Go to Tools -> Data Connections -> Click on the "Add " button and you will see the wizard shown below: Choose the "Receive data" option and click on the "Next" button





























ii. Choose the "Web service" option





























iii. Enter the correct URL as mentioned here, URL for root level site collection should be: http://nintex/_vti_bin/nintexworkflow/workflow.asmx?WSDL
 
for eg URL for a site collection with /sites as managed path should be: http://nintex/sites/sitecollectionname/_vti_bin/nintexworkflow/workflow.asmx?WSDL

If your site collection has also a sub site, then your URL should be http://nintex/sites/sitecollectionname/subsitename/_vti_bin/nintexworkflow/workflow.asmx?WSDL





























iv. Select the web service "GetRunningWorkflowTasksForCurrentUser and click on the "Next" button





























v. Click on the "Next" button





























vi. Click on the "Next" button (let the check box remain unchecked)





























vii. Uncheck the check box option " Automatically receive data when the form is opened"





























Similarly make a web service receive data connection for ProcessTaskResponse nintex web service as well.

d. InfoPath Form Options: We need to set the InfoPath form load options correctly. We need to configure Rules and Actions to ensure two different Views are shown for the Requestor and Approver. We also create a string field namely RequestStatus in InfoPath form, this field displays the Current Status of the Request in the read-only mode in the InfoPath form, this field is updated by our Nintex workflow to set the correct Request Status as per the flow of the workflow.

We also need to get the Task information for the current user who opens up the InfoPath form. Here is where our InfoPath webservice: GetRunningWorkflowTasksForCurrentUser comes into picture.

To set Form Options go to: Tools -> Form Options -> Rules -> Add a new Rule





































i. First we check whether the FileUrl is not blank condition, we need to create a string data source field in our InfoPath form for eg: FileUrl which gets updated by the Nintex workflow using the workflow activity "Set Item Value". Our nintex workflow sets the FileUrl to the current server relative url for the current item on which the workflow is running.

ii. We create a new Rule i.e Load Workflow Information, here we check whether FileUrl (data source field) is not blank for the Rule Condition to execute, see snapshot below
























ii. We then assign the value of FileUrl (local data field generated by the Nintex workflow) to, GetRunningWorkflowTasksForCurrentUser web service input parameter: fileUrl and then query the web service using the action "Query using a data connection" in InfoPath.

iv. This gets all the task related information for the current InfoPath form item on which the nintex workflow has been attached like SharePointTaskId, HumanWorkflowID, WorkflowName, Comments, WorkflowName, WorkflowInstanceId, TaskName, TaskType (i.e. Approval, Review, Collect Data) etc. We need the SharePointTaskId, as it will be used by the ProcessTaskResponse webservice. We also need to check whether task has been created for the user who is currently opening up the InfoPath form.

e. InfoPath Views: The InfoPath form is designed to handle multiple Form Views within the same form. This helps us seperate our Requestor forms and Approver forms.

Without much effort I can create two different Views one for the Requestor and another one for the Approver and depending on the workflow needs for a Reviewer too.

Hence, Views addresses the Role management aspect of a Business Process workflow application.

In order to create an InfoPath View -> Go to Design Tasks Pane on the right -> Views -> Add a New view

You can even copy and paste table/structure from the existing view and later change it as per your requirements.

NOTE: This new View will always refer to the same underlying XML schema/data source, InfoPath just creates a new XSLT per view and not the XML schema/data source.

f. Approvers View:

i. By now we assume that the above InfoPath Expense Report form has been duly filled in by the requestor and submitted for Approval. The workfllow has already started and it has created and updated the FileUrl (local field of the published InfoPath form).

ii. The workflow has also created a task for the Approver in the Workflow Tasks list. He has also received an email with the Item URL asking him to take some action on the request.

iii. So when Approver clicks on the Item URL sent to him via notification email, an InfoPath form opens up. Remember we have to setup predefined conditions on Form Load to Switch Views as per the Task Type and other conditions, see snapshot for Rules and Conditions on form load:































iv. The Approver gets to see the "Approvers View" after form loads and the above rules execute properly, see snapshot






The InfoPath Approval Task form above has a multi-line Comments field, Approve, Reject and Cancel buttons respectively.

g. Process Task Response:

i. The Approver fills in his comments and clicks of the "Approve" button, it is like completing the task assigned to him. But how does Nintex know of it? Here is where Nintex's second web service ProcessTaskResponse. plays a role in completing the task on behalf of the Approver.

ii. We need to configure some Rules and Actions on click of the Approve and Reject buttons, see snapshot below:

For Approve button:

























For Reject button:


























Here we set the ProcessTaskResponse webservice input parameters as follows:

1. spTaskId - SharePointTaskId (returned by the former webservice)

2. outcome - Approved (if approved) or Rejected (if Rejected) (you can have either Approved, Rejected, Continue as outcome)

3. comments - Approver Comments multi-line text field

Then finally we execute the Process Task Response using the InfoPath action "Query using a data connection"

In this way using the two Nintex Web services, we have succeeded in integrating InfoPath form with our Nintex workflow.


Important Information:
Submitted, RequestStatus and FileUrl are fields in the InfoPath form.

a. Submitted is an InfoPath form field and is set to false by default, then as the user clicks on Submit button, we set it to true and use it as a condition in the Form Load options. We configure Nintex workflow's "Wait Until" activity, as we do not want the workflow to start until Submitted value is True.

b. RequestStatus can be set either from Code Behind or Nintex Workflow’s Set Field Value activity.

c. FileUrl needs to be set in the Nintex workflow’s Set Field Value activity as: Current Item’s Server Relative Url.

This will be used as an Input parameter for the GetRunningWorkflowTasksForCurrentUser webservice. It fetches the task information like SharePointTaskId and TaskType for the current user who is trying to open up the InfoPath form. The same SharePoint TaskId will be used to complete his task, using the Process Task Response webservice.

We use it to determine the type of user and task assigned to him and switch Views respectively.

Part 2 covers the correct way of deploying InfoPath forms as Content Types and how to associate them to a particular list/library in SharePoint.

Feel free to share your comments and ask me in case of any doubts.

You can also follow me on Twitter: http://twitter.com/Mehul_Bhuva

I also blog my SharePoint Insights http://www.sharepointinsights.com/