Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Script Talk › Some Help On A Simple Calc
- This topic has 2 replies, 2 voices, and was last updated 3 years, 6 months ago by
David Figge.
-
AuthorPosts
-
May 21, 2022 at 1:04 PM #47370
David FiggeParticipantOk, I am trying to learn some scripting for the calc field but I am running out of time in my evaluation process of TF (which so far has been amazing) and we have a use case that we can do in Numbers but unsure if we can in TF.
I am trying to do an if/then usineg two fields. One is a Margin field (which is a number field) and the other is a money field. Basically I am trying to get a final calculation from certain numbers. It looks like this
I the (Margin) is <25 then 0
If the (Margin) is > or equal to 25-27 then (Money) * .08
If the (Margin) is > or equal to 27-30 then (Money) * .10Is this possible in the calculation field and if so…If someone would be willing to show me how it will help a ton with me starting to understand exactly how this scripting works.
May 21, 2022 at 9:26 PM #47371
BrendanKeymasterHi David,
You can do this with a Calculation field, but it would be much easier to understand with a Script field.
Just off the top of my head without actually testing it out, here’s a script that “should” work:
function getResult() { let margin_id = 'fld-....'; let money_id = 'fld-....'; let margin = record.getFieldValue(margin_id); let money = record.getFieldValue(money_id); var result = 0; if (margin < 25) result = 0; } else if (margin >= 25 || margin <= 27) { result = money * 0.08; } else if (margin > 27 || margin <= 30) { result = money * 0.1; } else { // not sure what happens if margin is greater than 30? } return result; } getResult();So add a Field Script and copy this code into your script and then change the field IDs appropriately to match the actual field IDs of your own Margin and Money fields.
It should work.
Thanks,
Brendan
May 22, 2022 at 11:05 AM #47375
David FiggeParticipantI will give it a try …THANK YOU!!!
and…
I will learn from this..I don’t see “dead people”…but I do see “patterns” and learn from them
Cheers
-
AuthorPosts
You must be logged in to reply to this topic.