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/

31 comments:

  1. I'm having trouble with a few steps.
    1. How is the FileUrl getting populated on form submission?
    2. Where is the RequestStatus field coming from in the switch to Approver view fields?

    ReplyDelete
  2. Hi,

    1. FileUrl is a local field in the InfoPath form Data Source (but not visible to the user) and will be set by your Nintex workflow, in the Nintex workflow we use the "Set Field Value" activity, where the FileUrl = Current Items Server Relative Url (may be I ll update the post with a snapshot soon)

    2. RequestStatus again is a local field in the InfoPath form Data Source, visible as a Read Only field, again I use the Nintex Workflow "Set Field Value" activity to set the Request Status as per the workflow stage.

    ReplyDelete
  3. Interesting article buddy. Thanks sharing it with the rest of us. :)

    Vadim Tabakman

    ReplyDelete
  4. Hi, a good reference. Just for completeness: if you are not using the default task list "Workflow Tasks", you need to use the ProcessTaskResponse2 method instead so you can specify the name of the task list as a parameter. Regards

    ReplyDelete
  5. Is it possible to use this with the request data action? I have a third outcome for my approval tasks so currently use request data to accommodate that.

    Great post though, never knew anything like this was possible! :)

    ReplyDelete
  6. Hi Stef,

    With Nintex Request Data action, you can use the same Process Task Response web service to complete/update the task information. The outcome that you need to pass in this case would be "Continue", unlike "Approved" or "Rejected" in case of Approval Task.
    Also the Task Type for this task will be "Collect Data"

    ReplyDelete
  7. Very nice reference!

    Which Nintex action do you use to create the tasks?

    I am looking forward to see the screen shot of you Nintex workflow.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. hi this is mahendran , i have one doubt in this article, here you didn't declare field contorls (SPTaskID,outcome)then will u assign the value,please tell me

    ReplyDelete
  10. SPTaskID,outcome and comments are the input parameters, we need to pass for Nintex webservice: Process Task Response.

    ReplyDelete
  11. I'm currently using nintex workflow on a sub site within my site like : http://domain.com/portal .

    do i use http://domain.com/_vti_bin/nintexworkflow/workflow.asmx?WSD or
    http://domain.com/portal/_vti_bin/nintexworkflow/workflow.asmx?WSD
    ?
    I created my form by your article but when i click on approve button an "An error accrued accessing data source" error shown.

    whats wrong?

    ReplyDelete
  12. what is Outcome variable?
    I must use string "Approved" or "Rejected" for input query of process task?

    ReplyDelete
  13. Hi Aria,

    You need to use http://domain.com/portal/_vti_bin/nintexworkflow/workflow.asmx?WSDL

    i.e. the Subsite URL where you are going to create the Nintex workflow.

    The tasks created out of this will get created in the Tasks list of the sub site.

    ReplyDelete
  14. Hi,

    When using ProcessTaskResponse webservice for Approval task,
    you need to pass 3 parameters:
    outcome: can be either Approved or Rejected
    SPTaskId: TaskId retrieved from GetRunningWorkflowTasksForCurrentUser webservice
    and
    comments: which is optional

    ReplyDelete
  15. Can u publish the infopath form. Because not able to check the rules. While clicking on approve button getting one error saying value does not fall within the expected range

    ReplyDelete
  16. Hi

    I have the exact scenario and am trying to use the solution given above. However, although I do not see any error, my task is not getting updated.

    I am using Process Task Response and in the Nintex SDK that it is obsolete now. They have now come up with Process Task Response 2.

    However, when I use Process Task Response 2, it fails to fetch the task list.

    Any pointers to what I could be doing wrong.

    Thanks

    ReplyDelete
  17. Which Nintex build version are you using? I believe ProcessTaskResponse is not deprecated/obsolete.

    What is the name of your task list where all these tasks get created? If your task list name is "Tasks", then try renmaing it to "Workflow Tasks", then try approving/rejecting the items.

    Also have you passed in the parameters correctly. I believe you have used the Approval task activity correctly.

    ReplyDelete
  18. UPDATE : "Submitted" is an Infopath hidden text field created within the main data source. By default the value assigned to this field is false, but when the user clicks on Submit button it is set to true

    ReplyDelete
  19. I have used nintex web service method in the InfoPath form to query the active tasks created through Request Approval action for a list item.
    I have used the method GetRunningWorkflowTasks instead of the GetRunningWorkflowTasksForCurrentUser method that gets active tasks for the current user.

    Earlier this was working as expected but it has suddenly stopped working. Now it fetches only the tasks that are pending for the current logged in user.

    This is difficult as we have admin functionality that should allow them to act on any outstanding tasks for the current item.

    ReplyDelete
  20. Please I couldn't get "Submitted" and "RequestStatus" fields when trying to set the condition for Manager Approval, the part you treated under Approver View above. Is there anything I have not done right or should I just take them as hidden objects and assume they will set to the correct value by default? please throw more light on that. Thanks

    ReplyDelete
  21. I assume the normal way of having the Nintex workflow do all the work instead of running the 2 webservices can still be used but requires a little more work to make sure the person opening the IP form is actually the person who needs to approve it.

    How do the webservices handle an AD group of approvers?

    ReplyDelete
  22. Can you please provide a list of the fields you created in the form that interact with the workflow?

    ReplyDelete
  23. Hi Mehul, i'm using infopath 2007 and nintex 2010.
    i've already create 1 form using infopath which approve and reject button is hidden in first time. And after the requester submit the form, the approver cannot open the form.
    The error said "An error occured while trying to connect to a web service"

    Can you help me?

    ReplyDelete
  24. Hi Mehul
    Great information. Thanks!
    If possible, please could you include a screenshot of the Approval Workflow that you've created in Nintex. I just want to make sure I put in the coreect Update List Items and request Approval items.

    ReplyDelete
  25. hi,
    I have created my event handler in visual studio.Now i want to use nintex web service in there s a web reference..Can you please guide me how can i accomplish that.Waiting For your reply.

    ReplyDelete
  26. Hey, Do you have the xsn and the nwf file this tutorial?

    ReplyDelete
  27. I got the same issue "An error occured while trying to connect to a web service".

    ReplyDelete
  28. Can someone please do the above on Infopath 2010 and particular attention to fileURL update

    ReplyDelete
  29. Hi Mehul,

    Can you throw some light on how to pass the data for the request data action. I want to pass the data/field to the workflow variable from Infopath and mark the request data action complete.

    ReplyDelete
  30. Hi Mehul,

    I added approve and reject buttons on manager's view in my infopath form. How can I make it work to connect to the Nintex workflow?

    ReplyDelete