Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

Symptoms

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.

↑ Back to the top


Cause

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.
xdMath:Avg(//dfs:dataFields/tns:UntypedDataSetQueryResponse/tns:UntypedDataSetQueryResult/ns1:NewDataSet/ns1:untypedDataSetTable/ns1:id)
However, if the XPath expression is truncated like the following example, this problem occurs.
xdMath:Avg(//ns1:NewDataSet/ns1:untypedDataSetTable/ns1:id)

↑ Back to the top


Workaround

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

↑ Back to the top


Status

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

↑ Back to the top


More information

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.
    [WebMethod]
    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;
                            untypedDataSetTable.Rows.Add(row);
                }
    
                return untypedDataSet;
    }
    
    Note For more information about how to create an XML Web service by using Microsoft Visual Basic or Microsoft Visual C#, visit the following Microsoft Developer Network (MSDN) Web site:

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.
    sum(dfs:dataFields/tns:UntypedDataSetQueryResponse/tns:UntypedDataSetQueryResult/ns1:NewDataSet/ns1:untypedDataSetTable/ns1:id)
  9. In the Insert Formula dialog box, replace the existing XPath expression with the following XPath expression, and then click OK two times.
    sum(//ns1:NewDataSet/ns1:untypedDataSetTable/ns1:id)
    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.

↑ Back to the top


Keywords: KB891162, kbbug, kbtshoot, kbxml

↑ Back to the top

Article Info
Article ID : 891162
Revision : 4
Created on : 11/16/2007
Published on : 11/16/2007
Exists online : False
Views : 388