Simple calculation is driving this newbie crazy - InfoPath Dev
in

InfoPath Dev

Simple calculation is driving this newbie crazy

Last post 07-30-2013 06:29 AM by Poppins. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-03-2007 03:42 PM

    Simple calculation is driving this newbie crazy

    I'm so new at  this I'm not sure where to begin.  I've made a InfoPath 2003 form and connected it to a SharePoint 2003 forms list.  That all works great.  Now I'm trying to get a little fancier on data integrity.  My application is tracking activities related to energy consumption.  I've added a Options Button to indicate whether the item increases or decreases energy consumption.  After the button is selected, i want to convert the numbers entered for consumption and cost such that decreases are negative numbers and increases are positive numbers.  I was thinking a simple equation like multiplying the absolute value of the entered consumption amount by -1 if the decrease option button was selected, or +1 if the increase option was selected.  I thought the best place to do this is add an OnAfterChange Event to the Validation and Event Handlers for the Option Button's properties.  The Microsoft Script Editor - script.js opens and I'M LOST!  How do I reference the data field name? Assign a new value to it? And, reference the math function abs()?

     Thanks for helping a beginner.

     --- Bruce   

  • 12-03-2007 04:10 PM In reply to

    Re: Simple calculation is driving this newbie crazy

    Hey Bruce.

    I think you are making this more complicated then you need to. One of the great things about InfoPath forms is that you can do most things without code.

    Open up the control (double click) which the user makes the selection from and then create a rule. You should set a fields value as the action, select your target field, and then build your formula for calculating your value.

    You should be able to do everything you are looking for and it is a much simpler and controlled environment and it will validate your formula too.

  • 12-03-2007 04:50 PM In reply to

    Re: Simple calculation is driving this newbie crazy

    Clay,

    Thanks for the quick response.  When i create a rule and then set a field's value, I can't use an absolute value function.  There are only minimal math functions (avg, boolean, ceiling, etc.).  ABS is not one of them.  I tried to square the number and then take the square root, but it didn't have the square root function and didn't like the (x * x)^.5 format either.  Without a ABS type function, I would need to verify that each of the data points were correctly signed (+/-) by the person entering the data.  I'm sure I'm missing something obvious.  Thanks.

     

  • 12-04-2007 09:28 AM In reply to

    Re: Simple calculation is driving this newbie crazy

    I would lke to know how you are gathering the input. My thought was you should not need the ABS function.

    If you had options buttons -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 then it would be pretty straight forward and you would not need this validation, you could just use the values of the option buttons.

    I am assuming then they select positive or negative and then enter a value or just select a numeric option.

    You would put logic in a rule that said if selection equals negative 0 - numeric ( which would give you your negative value) otherwise the numeric.

    Let me know what the data values you have or attach your form and I can maybe help you better.

     

  • 09-23-2010 01:15 AM In reply to

    Re: Simple calculation is driving this newbie crazy

    I needed to calculate an absolute value in a formula in InfoPath. I used a conditional expression.  So for example say you have a field called MyNumber and you want to calculate its absolute value, you edit the formula (either as an expression box or as the default value of a text box).  Check the Edit XPath checkbox and enter the XPath expression:

    (1 - (my:MyNumber < 0) * 2) * my:MyNumber

    The expression (my:MyNumber < 0) is 0 if MyNumber is positive or zero, and 1 if MyNumber is negative.

  • 07-30-2013 06:29 AM In reply to

    Re: Simple calculation is driving this newbie crazy

    Look at this link: http://www.braintrove.com/id/70

    Infopath Designer
    Filed under:
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.