Ok, 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) * .10
Is 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.
Hi 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
I 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