Copy link to clipboard
Copied
Need help on some conditional formating.
I have a drop down where the user choose one of two contract type. I've assigned export values to each of the contract type (2 or 4).
Then I need another field to format the number to either 2 decimal places or to 4 decimal places.
This is the first time I'm attempting something like and I'm learning all of this as I go.
I've looked at some resources but I'm not seeing something similiar to this.
I'm thinking I start with
if contract = this.getField("Contract type").value =4;
then
so the then would be the formatting, but I've not clue how I write that.
Then I know I have an else which would be the formatting for 2 decimal places.
These figures are monetary, so if I can include that in the formating would be great.
Help!
Clueless beginner
Copy link to clipboard
Copied
Try this:
var drop = this.getField("Contract type").valueAsString;
if(drop == "2")
event.value = util.printf("%.2f", event.value);
else if(drop == "4")
event.value = util.printf("%.4f", event.value);
Copy link to clipboard
Copied
Thank you that worked. I'm trying to build on it now...
So the next field CYP Plus CPI needs to be a formula but formatting based on the that drop down...
so the result of var CYP is going to be the event.value I think but how to I make it do that.
var CPI = this.getField("CPI").value * this.getField("CY Food").value; // amount of CPI increase
var CYP = Increase + this.getField("CY Food"); // Current Year Plus CPI Increase
Copy link to clipboard
Copied
I finally figured it out. I'm good to go. I caught my error in the code above too.
Copy link to clipboard
Copied
You didn't declare 'Increase' variable, and you are missing '.value' after: this.getField("CY Food")