I have an InfoPath 2010 form that creates a new Sharepoint list item. The form has, in essence, one input field and one output field. If something gets entered in the input field then some calculation is performed and I want the result to show up in the output field before the user clicks "OK" or "Reject". As the calculation is somewhat complicated I need to do it in code, not through rules.
I am doing this:
private void CalculateOutput()
{
XPathNavigator main = MainDataSource.CreateNavigator();
XPathNavigator service = main.SelectSingleNode("my:meineFelder/my:serviceValue", NamespaceManager);
double serviceValue = service.ValueAsDouble;
double output = 3*serviceValue; // much abbreviated version
// output now has the correct value
XPathNavigator outputNav = main.SelectSingleNode("my:meineFelder/my:output", NamespaceManager);
//Remove the "nil" attribute (otherwise we get an error when the field is a double instead of a string)
if (outputNav.MoveToAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance")) outputNav.DeleteSelf();
outputNav.SetValue(output.ToString());
}
My problem is that everything works fine in the InfoPath preview but once I deploy the form and run it in the browser the output field does not get updated, i.e. I cannot see the result of my calculations.
I have tried .ReplaceSelf (with OuterXML), with zero result. I have also played with assigning the result to another field and thereby firing an "set field value" rule, also to no avail.
If I submit the form, the output value is saved OK but I'd really like the user to see the output field before submitting. I guess I need a way to refresh the form but I can't see how.
Any Ideas? Thx a lot.