Datapolis Process System SDK


Home > WBInterface > Using WBInterface in Microsoft InfoPath 2010

Using WBInterface in Microsoft InfoPath 2010



In this section you will find an example how to use WBInterface in InfoPath form.



Scenario: Creating an InfoPath list form which abides by Datapolis Process System-set field permissions provided by Datapolis Process System Interface method GetWBItemInfo.

1. Let's consider a simple workflow:


2. When our sample workflow is in state State1, users in the role of Banned Users will have the following permissions to fields of the item on which the workflow is running:


3. To create an InfoPath form, first run SharePoint Designer, select the list you prefer and open its settings. There, click the Design Forms in InfoPath ribbon button and chose the content type you wish the form to be bound to.




4. Microsoft InfoPath will be opened with the form generated for the existing list fields. First you have to create a new data connection. Click the Manage Data Connection link in the Actions section of the Fields toolbox. In the Data Connection window that will open, click Add.


5. In the first step of the Data Connection Wizard, select the Create a new connection to option and chose Receive data. Click Next.


6. In the second step, select SOAP Web service.


7. In the third step, provide the URL where the WBInterface web service exists. The URL is usually in the following form: http://web_application/site/_layouts/Datapolis.WorkBox/WBInterface.asmx.


8. In the fourth step, select the GetWBItemInfo web method and click Next.


9. In the fifth step you have to assign the web method's parameters. In our case these parameters are:

listURL - URL address of the list from which we want to retrieve data. In this scenario it's the same list for which we create the form.
itemID - ID of the list item to retrieve. Currently you can provide any value for the parameter, it will be changed later.



10. Follow the next steps of the wizard, leaving default options, until you reach the last step of Data Connection Wizard, where you should unselect the Automatically retrieve data when the form is opened checkbox.



Then click Finish to return to Data Connection window.

IMPORTANT: If the list for which you build the form is not on a root site of your web application, you have to perform some additional steps:


a. First, create a new document library of Data Connection Library type (if you don't have one already).


In Data Connection window click Convert to Connection File button. Provide an URL address to a udcx file located in the Data Connection Library on the site. The file doesn't have to exist, it will be created automatically.



b. Next, go to the Data Connection Library and download the file. Using any text editor (Notepad, for instance) open it and note that the ServiceUrl point to a location in your root site. Modify it so that it points to a location in the sub site (like in wsdlurl node, but without the "?WSDL").



You can either just save the file and continue using it, or save the file with a new name. In the second case, the original file will still be available, but, if not used elsewhere, can be safely deleted.


In this tutorial we have changed the name to GetWBItemInfo-fixed.udcx for better clarity.


c. Upload the modified file to the Data Connection Library.

In the Data Connection window, remove the data connection you have created earlier and click the Add button. Data Connection Wizard will open, but this time select Search for connections on a Microsoft SharePoint Server option.



d. In the next step, click Manage Sites and in the new window add the sub site on which you are currently working. Close the window and go back to the wizard. You should see your site in the drop-down list at the top. Select it and the items of the Data Connection Library should be displayed below.


e. Select the file you've uploaded earlier and click Next.


f. The next steps are the same as before.

11. Now you can define more complex logic offered by InfoPath. Because in this demonstration we want to use Datapolis Process System field permissions, we will set up a formatting rule which will disable or enable form fields accordingly.


First we must query Datapolis Process System Interface web service for the specific item. As you recall, in the Data Connection Wizard, when we have set up GetWBItemInfo method's parameters, we have explicitly set the itemID parameter to 1. This would cause the form to always retrieve information of the list item with ID equal to 1, which is obviously not what we want. We need to query for the item for which the form is being displayed.


In order to do this, select the Data tab on the ribbon, and click the Form Load button. In the Rules toolbox on the right side of the screen, click New and select Action.



12. In the new window, click the Add button next to "Run these actions" and in the Rule Details select Set a field's value action.


13. Select the query field you wish to change by clicking the icon on the right of the Field textbox. In the Select a Field or Group window, click Show advanced view, select GetWBItemInfo-fixed option in the Fields drop-down list, and navigate to myFields->queryFields->tns:GetWBItemInfo->itemID. Accept the selection by clicking OK.


14. To set Value, click the icon on the right, then click the Insert Field or Group button and select ID from the field list.


15. Optionally, if you haven’t done it in Data connection settings or if you want to get information about other list, you can set listURL parameter. In order to do so, add another Set a field's value action to the previously created Load Form rule.


16. Select the listUrl query field in the same way as you did with itemID.



17. Now select the value source; for instance, use the built-in SharePointListUrl function by clicking Insert Function button and selecting URL -> SharePointListUrl.


18. Accept all the open windows and go back to InfoPath form designer.
19. In the Rules toolbox add a new action, this time Query for data. As Data connection select GetWBItemInfo-fixed.


Now the form will query GetWBItemInfo method of the Datapolis Process System Interface web service, passing the actual ID to the itemID parameter.



 We advise adding the rule condition checking that the ID field has a value to avoid querying the web service when adding a new item. You can achieve this by clicking the None - Rule runs when form is opened link under Condition, in the Form Load rules. In the Condition window, in the first drop-down list choose the Select a field of group and select the ID field. In the second list, choose the is not blank option. Accept the condition by clicking OK.

20. We can set the formatting rule to disable specific field if the current user should not be able to edit them.


To add the rule, select the Title field and click Manage Rules button on the ribbon. In the Rules toolbox on the right side of the screen, click New and select Formatting rule.



21. Name the rule to your liking (for instance, "Disable field") and click None below Condition. From the first drop-down menu select The expression and paste the following script:


normalize-space(xdXDocument:GetDOM("GetWBItemInfo-fixed")/dfs:myFields/dfs:dataFields/tns:GetWBItemInfoResponse/tns:GetWBItemInfoResult/tns:FieldsAllowedToEdit/tns:WBFieldInfoCollection/tns:WBFieldInfoCollectionElement/tns:WBFieldInfo/tns:Title[. = "Title"]) = ""


Please take a while to familiarize yourself with the expression above. The particularly interesting items are the following:

a. GetWBItemInfo-fixed – the name of the data source you have set up earlier. If you have followed the tutorial, it's the file we've created in step 10b.
b. FieldsAllowedToEdit - it's a property of the WBInterface's WBItemInfo class. The property is a list of the fields that the context user is allowed to edit. Other useful property is FieldsAllowedToDisplay, containing the fields that the context user is allowed to see.
c. Title - the name of the column to search for in the FieldsAllowedToEdit list. It's the display name of the column, not the internal name. Note that the name can vary, depending on the language of the site, or even when someone modifies the column. If such situation occurs, you have to update the expression to reflect the column's current name.

If the form does not behave as intented, please make sure you've correctly entered the expression and provided valid information (i.e. the above three items)



22.Because we want to disable the field when it's not supposed to be editable for the user, select the Disable this control checkbox to apply the property we want to set when the rule executes.



 If you need to hide the field (the user should not be allowed to view the field), you can use a rule similar to the one described in step 17 - the difference would be in changing FieldsAllowedToEdit to FieldsAllowedToDisplay and checking the Hide this control. You should put this rule before the one to disable the control - otherwise hiding will not work.





 We advise adding the rule condition checking that the ID field has a value to avoid querying the web service when adding a new item, as described earlier.

23. Now the form is ready and ready for publishing. If a user in Banned Users role of the sample workflow opens the form to execute the End action, the Title field of the form will be disabled.





Occasionally when accessing the InfoPath Launch Form you may experience an error message similar to the following:




This error is a known issue of the InfoPath form viewer control, but it does not hamper the form's functionality. After closing the message, the form can be used normally.