BUG: The results of the calculations in an InfoPath form are incorrect in InfoPath 2003 (891162)



The information in this article applies to:

  • Microsoft Office InfoPath 2003, Service Pack 1 (SP1)

SYMPTOMS

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.

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)

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

STATUS

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

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 2003.
  2. On the File menu, click Design a Form.
  3. In the Design a Form task pane, click New from Data Connection.
  4. In the Data Connection Wizard, click Web service, and then click Next.
  5. Click Receive data, and then click Next.
  6. 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.
  7. Select the UntypedDataSetQuery method, click Next, 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 File menu, point to Preview Form, and then click Default.
  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.

Modification Type:MajorLast Reviewed:4/5/2005
Keywords:kbXML kbtshoot kbbug KB891162 kbAudDeveloper