Bulleted items are user-entry
Numbered items are calculation
Total claim request is simple and I don’t need help on that
Formula I need should allow for: Maximum allowable is equal or smaller than Maximum refund for category.
So basically IF Total claim request is =< than Maximum refund for category, then Maximum allowable = Total claim request. ELSE = Maximum refund for category
c.value is the amount that is determined based on whether the actual claim amount - a.value - is equal or smaller than b.value. If it is larger than b.value then c.value is b.value.
In simple English -
You are entitled to $800 maximum funding (b.value)
Your application is for $1,200, for example (a.value)
Your Max Funding Amount is $800 (c.value) because $1,200 is MORE than the $800 max.
Of course an applicant can o this math by hand. I just want to automate it because there’s nothing better than spending oodles of time to save 30 seconds later.
Great job! Ya, you could tighten this up a little. You could get rid of that last else statement by changing the condition on the if slightly. And doing that would then allow you to change the current else if to just an else and you wouldn’t even need a second comparison. I’ll give you a hint: In addition to the > and < operators there are also >= and <= operators.
Also, I would recommend you choose better variable names. Instead of A I would probably use amount and for B I would probably use maximum. That way you don’t have to think about what A and B actually represent as you are looking at the code since the variable names will tell you exactly what they are.
I don’t know anything about Adobe/Foxit but I’m assuming (hoping) that getField is actually returning numbers and not strings. Because if it is returning strings then you will get some nasty surprises. I would suggest you test with the Amount set to 90 and the Maximum set to 100 and make sure it comes out correctly.
Regarding variables’ names, great tip. It could be the same as the variable itself, makes the flow and thought pattern easier.
It is returning numbers as the entry fields are set to numbers only. I tested it as suggested, and a dozen other ways, appears to be pretty solid. Is there any other way that string vs number could be checked?
Great question. I should have included this in the first place.
Yes, you can use the typeof operator to see what the actual type of a value is.
var A = this.getField("Amount").value;
console.log(typeof A);
The console.log method will print the result of typeof A to the browser’s console and then you would hopefully see “number” instead of “string”. I don’t know about the environment you are working in and so I’m not sure if console.log will work for you? If not then you’d have to figure out another way to see it.