Formula based on drop down value - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Formula based on drop down value

Last post 05-08-2020 08:35 AM by DS7298. 11 replies.
Page 1 of 1 (12 items)
Sort Posts: Previous Next
  • 01-19-2012 04:09 PM

    Formula based on drop down value

    I need to set a textbox value to be a simple calculation based on the value of a drop down box

    Normally I would code this as...

    if(dropdown == "refer") {
    TotalCost = Rate*hours
    } else {
    TotalCost = Flatfee * 10
    }

    Where TotalCost, Rate, hours and flatfee are textbox values
    I can set simple calculations/forumlas in Infopath but am not sure how to do the IF THEN ELSE logic within Infopath

    This will ultimately be a browser based form

  • 01-19-2012 07:04 PM In reply to

    Re: Formula based on drop down value

    DropdownFormula.xsn

    Hi: 

    I've attached a sample for you.

    Hope that helps!

    Jo-Anne Alfafara
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 01-19-2012 07:27 PM In reply to

    Re: Formula based on drop down value

    Thanks Jo-Anne.
    Was this done in code or using a rule?

    After I made my post I looked around some more and realised I could do this by adding a rule to the drop down. I'm not sure how to dismantle an xsn file so couldn't look to see what you had done.

  • 01-19-2012 07:36 PM In reply to

    Re: Formula based on drop down value

    No code, just rules. Right-click on the XSN on the location where you saved it and select Design. It will open InfoPath in design mode. Please check out the rules in the dropdown by clicking on the dropdown box and then open Manage Rules in the Home tab (that is, if you're  using InfoPath 2010). In InfoPath 2007, you can right click on the dropdown and select Rules.

    Jo-Anne Alfafara
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 01-19-2012 07:44 PM In reply to

    Re: Formula based on drop down value

    Thanks again, looks like we did almost the same thing. My rule said if = to this then set this field value.
    If that is not the case then the value is set using a formula on a different field.

    I will use your idea of having 2 rules on the drop down. That way it would be cleaner and less chance of rule 1 over writing formula 2

  • 01-19-2012 07:52 PM In reply to

    Re: Formula based on drop down value

    Glad it work! =)

    Jo-Anne Alfafara
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 01-23-2012 01:38 PM In reply to

    Re: Formula based on drop down value

    One other thing....

    My drop down appears before the textboxes in the formula, the rules will only "fire" if the drop down box is used after the values have been entered into the form.
    Is there a way to tie the textboxes to the drop down in a way so that when they are changed or have values entered, the rules re-run?

  • 01-23-2012 01:59 PM In reply to

    Re: Formula based on drop down value

    You'd just need to add similar rules to your fields bound to the text boxes - rules only fire when the value of the field the rule is on changes. You may also want to use a default value instead - but from your initial post, it sounds as if the calculation has conditions, so a default value may not be appropriate for your scenario.

    Hilary Stoupa

  • 01-23-2012 03:13 PM In reply to

    Re: Formula based on drop down value

    Anyway I could do this (see rules inspector in image) without having to cover every text box? Would be great to be able to refire the dropdown function when a textbox value is changed or onBlur but if this can't be done i'll need to cover backwards and forwards.... but preferably not having to attach these 2 rules to every textbox included in the formulas?

     

    Rules inspector

     

     

  • 01-23-2012 03:40 PM In reply to

    Re: Formula based on drop down value

    It seems to me that you could use a default value for "BalanceCollectBySupplier", since ReceivedByOffice gets set to 0 in the first ruleset. I'd think that having BalanceCollectBySupplier default to TotalCost - ReceivedByOffice would be the same for either ruleset, right?

    So, the ReceivedByOffice rule seems to only need to be on this field - no other field change would affect it, right? That one would stay here....

    That leaves you with just the InvoiceThisOffice action.

    Here's a link to a blog post that talks about a way to create "conditional" default values. I'll warn you that I had a performance issue with this method once - but it was being used in a field in a repeating section that had quite a few instances, and both conditions included some kind of complex math.

    Hilary Stoupa

  • 01-24-2012 11:43 AM In reply to

    Re: Formula based on drop down value

    Thanks, that sounds a bit icky, I might just put the rule on the drop down 9as it is now) and add it to the last text box.

  • 05-08-2020 08:35 AM In reply to

    Re: Formula based on drop down value

     I liked your answer and was wondering how I would do a similar thing. I need the dropdown selection to simply fill a textbox the selection chosen.

Page 1 of 1 (12 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.