Skip to main content
July 23, 2020
Answered

Javascript to coy the value of a field if a condition is not met?

  • July 23, 2020
  • 1 reply
  • 800 views

Okay, if the field 'SalesPrice' is over 800,000 field 'LessThan' needs to show 0, but if 'SalesPrice' is less than 800,000 field 'LessThan' needs to match field 'SalesPrice'. How do I write this? And would this go in the calculate screen or Validate?

 

TIA!

This topic has been closed for replies.
Correct answer try67

Yes, as the calculate event of the LessThan field use this code:

var salesPrice = Number(this.getField("SalesPrice").valueAsString);

event.value = (salesPrice>800000) ? 0 : salesPrice;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 23, 2020

Yes, as the calculate event of the LessThan field use this code:

var salesPrice = Number(this.getField("SalesPrice").valueAsString);

event.value = (salesPrice>800000) ? 0 : salesPrice;

July 23, 2020

Thanks for the quick reply! Paste only 

 

var salesPrice = Number(this.getField("SalesPrice").valueAsString);

event.value = (salesPrice>800000) ? 0 : salesPrice;

??

 

If so, it didn't work.

try67
Community Expert
Community Expert
July 23, 2020

Yes, that's the full code.

Please be more specific. What happened when you use it, exactly?