BUG: The results of the calculations in an InfoPath form are incorrect

In Microsoft Office InfoPath 2007 or in Microsoft Office InfoPath 2003, when you use an InfoPath form that contains calculations, values from the OriginalData nodes may be included with values from the selected nodes that are used in the calculations. This behavior is unexpected. Therefore, the results of the calculations in the InfoPath form are incorrect.


This problem occurs when the calculations in the InfoPath form contain an XPath expression that starts with two slash marks (//). The OriginalData nodes are in the same namespace as the nodes in the DataSet object.

For example, the following calculation returns the correct results.


However, if the XPath expression is truncated like the following example, this problem occurs.



To work around this problem, use one of the following methods:

Use the selectSingleNode method, and specify the exact XPath expression that you want to use.
If you have to use the selectNodes method to create a multiple-selection XPath expression, select all nodes that you want to use under the first DataSet construct. For example, if you have a DataSet object that is named DataSet, use an XPath expression that follows the following format:full_xpath_to_DataSet[position()=0]//xpath_to_nodes_for_selection


Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the “Applies to” section.


Steps to reproduce the problem

Create an XML Web service

1. Create an XML Web service, and add a method that has the following signature:

The return type is the DataSet object.
The method name is the UntypedDataSetQuery method.
The parameter list is not applicable.
2. Add the following code example to the method.

public DataSet UntypedDataSetQuery()
            DataSet untypedDataSet = new DataSet();
            untypedDataSet.Namespace = "http://www.contoso.com/untyped";
            DataTable untypedDataSetTable = untypedDataSet.Tables.Add("untypedDataSetTable");
            untypedDataSetTable.Columns.Add("id", typeof(int));

            for (int addRowCounter = 1; addRowCounter <= 5; addRowCounter++)
                        DataRow row = untypedDataSetTable.NewRow();
                        row["id"] = addRowCounter;

            return untypedDataSet;

Create an InfoPath form

1. Start InfoPath.
2. In InfoPath 2007, click Design a Form Template.In InfoPath 2003, click Design a Formon the File menu.
3. In InfoPath 2007, click Web Service, and then click OK.In InfoPath 2003, click New from Data Connection, click Web service, and then click Next.
4. Click Receive data, and then click Next.
5. In the Enter the location of the Web service you want to use as your data connection box, type the location of the Web service that you created in the “Create an XML Web service” section, and then click Next.
6. In InfoPath 2007, select the UntypedDataSetQuery method, and then click Next two times.In InfoPath 2003, select the UntypedDataSetQuery method, and then click Next.
7. Type a name for this data connection, and then click Finish.

Test the form with XPath expressions

1. On the Insert menu, click More Controls.
2. Click the Expression Box control.
3. In the Insert Expression Box dialog box, click fx.
4. In the Insert Formula dialog box, click Insert Function. The Insert Function dialog box appears.
5. Select All for Categories, select sum for Functions, and then click OK.
6. Double-click double click to insert field. The Select a Field or Group dialog box appears.
7. Expand dataFields, select the id field, and then click OK.
8. In the Insert Formula dialog box, click to select the Edit XPath (advanced) check box. Notice the following XPath expression in the Formula box.

9. In the Insert Formula dialog box, replace the existing XPath expression with the following XPath expression, and then click OK two times.


Note You may have to adjust the previous string according to your namespace prefix.

10. On the standard toolbar, clickPreview Form.
11. Click Run Query on the preview form. You will notice that you receive 30 for the calculation. The expected output for the calculation is 15.


Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply

To prove that you're not a bot, enter this code
Anti-Spam Image