Expand my Community achievements bar.

Field Validation based off another field

Avatar

Level 1

I have a form that is near completion with only one exception using formcalc. I am having the most terrible time figuring this out.

In my form I have three fields: SpecialPromotion (number field), BrandDiscount (calculated-readonly, number field), and DiscType (dropdownlist).

DiscType and BrandDiscount are linked by the DiscType. If DiscType is "BWI" then BrandDiscount calculates discount off gross amount. If it equals "N/A" then BrandDiscount is zero (blank).

If a user enters a dollar amount higher than 0 in SpecialPromotion, then BrandDiscount is zero (blank) and DiscType equals "N/A". If the user selects a different option in Disctype then SpecialPromotion should zero out (blank).

Basically, if SpecialPromotion has a value then BrandDiscount does not apply and/or vice versa.

Currently, I have this as a validate script in formcalc but it is not working and I continually get a validation error. Please any help or suggestion would be very appreciated. Thank you in advance.

Here is the coding I have so far:

if (SpecialPromotion > 0) then
BrandDiscount = 0; &
DiscType = "N/A";
endif

if (DiscType == "BWI") then
SpecialPromotion = 0;
elseif (DiscType == "HIL") then
     SpecialPromotion = 0;
elseif (DiscType == "HAM") then
  SpecialPromotion = 0;
elseif (DiscType == "MAR") then
  SpecialPromotion = 0;
elseif (DiscType == "HYT") then
SpecialPromotion = 0;
elseif (DiscType == "SWD") then
SpecialPromotion = 0;
elseif (DiscType == " ") then
SpecialPromotion = 0;
endif

1 Reply

Avatar

Level 7

Would you be okay with moving this to an exit event on each? i.e., the first if/then goes in the exit event for the specialPromotion box, then the second one goes into the discType exit event.

Here's my solution:

form1.#subform[0].specialPromotion::exit - (FormCalc, client)

if ($.rawValue gt 0) then

          brandDiscount.rawValue = 0

          discountType.rawValue = "N/A"

endif

form1.#subform[0].discountType::exit - (FormCalc, client)

if (HasValue($.rawValue) and $.rawValue <> "N/A") then

          specialPromotion = 0

endif

Of course, I don't have a list of various "Brand Discounts" to add, so you may need to use that list of if statements instead of that quick check I did.

maybe something like

form1.#subform[0].discountType::exit - (FormCalc, client)

if (HasValue($.rawValue) and $.rawValue <> "N/A") then

          specialPromotion = 0

          if ($.rawValue eq "BWI") then

                    brandDiscount.rawValue = 15

          endif

          if ($.rawValue eq "HIL") then

                    brandDiscount.rawValue = 10

          endif

          ;etc.

endif

I left the check for "N/A" in the if statement in case the user happens to tab through that drop down box.