Calculated value not retained after InfoPath form is saved. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Calculated value not retained after InfoPath form is saved.

Last post 08-18-2011 09:42 AM by kcark1. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 08-16-2011 01:39 PM

    • kcark1
    • Not Ranked
    • Joined on 08-16-2011
    • Posts 8

    Calculated value not retained after InfoPath form is saved.

    First, let me start by saying I have about two weeks expereince with InfoPath forms and have run into this issue. 

    I have created a form where the field "AmountDue" will calculate the value based upon field "NoUnitsProvided" * field "ServiceRate".  If a payment has been made against a specific line item, I want to show the AmountDue as a negative value.  To do this, I have set a rule in the field "AmountDue" as follows: 

    Rule 1(ServiceType = "Service Payment")

    the acton defined to the above is as follows:

    =fx Set a field's value: . = (NoUnitsProvided * ServiceRate) * -1

    When entering the data values, the form and fields work as I expect and print with the expected negative value for payments.  The problem is when I save the completed form and later load to review the saved form, the negative values have not been retained.  The formula has reverted to "NoUnitsProvided" * "ServiceRate" and no longer considers the desired action. 

    Suggestions or direction would be much appreciated. 

  • 08-16-2011 11:54 PM In reply to

    Re: Calculated value not retained after InfoPath form is saved.

    What kind of form logic is setting the fields to their non-negative value?  It sounds like that's being re-triggered when the form is opened, perhaps due to the loading of a data source or something like that?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-17-2011 06:58 AM In reply to

    • kcark1
    • Not Ranked
    • Joined on 08-16-2011
    • Posts 8

    Re: Calculated value not retained after InfoPath form is saved.

    Thanks for the reply.  There is no external data source, the forms operates stand-alone just for the purposes of having an electronic form.  The default field value field "AmountDue" is "NoUnitsProvided" * "ServiceRate".  All fields relavent to the default value are found in a repeating table.  The repeating table has a total of 12 fields in it, 3 of which ("ServiceType", "NoUnitsProvided", and "ServiceRate") have a relation to the "AmountDue" field.  The "ServiceType" field is a  List Box with 5 possible selection, Basic, Minimal, Moderate, Intensive, and Service Payment.

    The premise I have used in defining the form is that the end-user will select a ServiceType, enter the "NoUnitsProvided" and the "ServiceRate".  The "AmountDue" field calculates "NoUnitsProvided" * "ServiceRate".  Again, this is the default value for the "Amount Due" field.  If the end-user selects a "ServiceType" of Service Payment, I have created a Rule the sets a condition of ServiceType = "Service Payment" and an Action of Set a field's value: . = (NoUnitsProvided * ServiceRate) * -1.

    This is where my issue begins.  When I complete the initial entry to the form, the calculations work fine and display properly.  After I save the form using file save as giving the form a unique name such as test13 and then open the form test13 to continue editing, the line items that were listed as "Service Payment" have now reverted to the default calculation of "NoUnitsProvided" * "ServiceRate" and do not consider the Rule.

    I know that this is a long winded explanation, but I hope this helps find a solution.

  • 08-17-2011 07:56 AM In reply to

    Re: Calculated value not retained after InfoPath form is saved.

    One thing that should work is to remove that rule and change the default value formula to:

    (NoUnitsProvided * ServiceRate) * (1 - 2 * (ServiceType = "Service Payment"))

    This will switch the value to negative when ServiceType is equal to Service Payment.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-17-2011 10:05 AM In reply to

    • kcark1
    • Not Ranked
    • Joined on 08-16-2011
    • Posts 8

    Re: Calculated value not retained after InfoPath form is saved.

    Thank you very much!  Worked like a champ.  Now since this is way beyond my basic understanding, why does it work?  What does the 1 - 2 do to make it work?

    Thanks again.

  • 08-17-2011 09:13 PM In reply to

    Re: Calculated value not retained after InfoPath form is saved.

    Within a mathematical expression, a Boolean expression (i.e. (ServiceType = "Service Payment")) is treated as a 1 when it is true and 0 when it is false.  So when ServiceType has the value "Service Payment", the (1 - 2 * (ServiceType = "Service Payment")) part evaluates to (1 - 2 * 1) -> (1 - 2) -> -1.  When ServiceType has another value, it evaluates to (1 - 2 * 0) -> (1 - 0) -> 1.  Nothin' to it! :-)

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-18-2011 09:42 AM In reply to

    • kcark1
    • Not Ranked
    • Joined on 08-16-2011
    • Posts 8

    Re: Calculated value not retained after InfoPath form is saved.

    That makes perfect sense now.  thanks for the explanation.
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.