Microsoft KB Archive/891162

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

Article ID: 891162

Article Last Modified on 11/16/2007

-

APPLIES TO


 * Microsoft Office InfoPath 2007
 * Microsoft Office InfoPath 2003, Service Pack 1 (SP1)

-



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.



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, use an XPath expression that follows the following format:

full_xpath_to_ [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 &quot;Applies to&quot; section.



Create an XML Web service
 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.</li> The parameter list is not applicable.</li></ul> </li>  Add the following code example to the method. [WebMethod] public DataSet UntypedDataSetQuery {           DataSet untypedDataSet = new DataSet; untypedDataSet.Namespace = &quot;http://www.contoso.com/untyped&quot;; DataTable untypedDataSetTable = untypedDataSet.Tables.Add(&quot;untypedDataSetTable&quot;); untypedDataSetTable.Columns.Add(&quot;id&quot;, typeof(int)); for (int addRowCounter = 1; addRowCounter <= 5; addRowCounter++) {                       DataRow row = untypedDataSetTable.NewRow; row[&quot;id&quot;] = 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:

http://msdn2.microsoft.com/en-us/library/Aa290754(VS.71).aspx

</li></ol>

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.
 * 1) 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.
 * 1) Click Receive data, and then click Next.
 * 2) 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 &quot;Create an XML Web service&quot; section, and then click Next.
 * 3) In InfoPath 2007, select the UntypedDataSetQuery method, and then click Next two times.

In InfoPath 2003, select the UntypedDataSetQuery method, and then click Next.
 * 1) Type a name for this data connection, and then click Finish.

Test the form with XPath expressions
<ol> On the Insert menu, click More Controls.</li> Click the Expression Box control.</li> In the Insert Expression Box dialog box, click fx.</li> In the Insert Formula dialog box, click Insert Function. The Insert Function dialog box appears.</li> Select All for Categories, select sum for Functions, and then click OK.</li> Double-click double click to insert field. The Select a Field or Group dialog box appears.</li> Expand dataFields, select the id field, and then click OK.</li>  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) </li>  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. </li> On the standard toolbar, clickPreview Form.</li> 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.</li></ol>

Additional query words: IP2007

Keywords: kbtshoot kbbug kbxml KB891162

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.