Skip to main content
December 14, 2022
Question

Conditional formating on a number

  • December 14, 2022
  • 1 reply
  • 628 views

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

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
December 14, 2022

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);

December 22, 2022

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
December 22, 2022

I finally figured it out.  I'm good to go.  I caught my error in the code above too.