Skip to main content
Participant
March 9, 2016
Answered

If blank then do not calculate?

  • March 9, 2016
  • 1 reply
  • 642 views

I'm attempting to create a custom calculation script for a discount field (in $) where it takes the value of a master discount field (in %) times the quantity of the item by the price. The issue is that I have the master discount field set to be blank should no value be entered and this seems to interrupt the calculation. I'm quite inexperienced with javascript so I'd appreciate it if you could take a look at my issue and let me know what I might need to do in order to fix it.

This is the simple formula that I need to get the required total:

(QTY1*UnitPrice1)*(Discount1/100)

I am attempting to say that if the value = blank/null then do not perform the calculation otherwise perform (A*B)*(C/100):

if (this.getField("Discount1").valueAsString=="") then ???

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 100 );

Thank you!

This topic has been closed for replies.
Correct answer try67

if (this.getField("Discount1").valueAsString=="") event.value = "";

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 100 ); 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
March 9, 2016

if (this.getField("Discount1").valueAsString=="") event.value = "";

else event.value = ( this.getField("QT1").value * this.getField("UnitPrice1").value ) * ( this.getField("Discount1").value / 100 ); 

d787685Author
Participant
March 9, 2016

Excellent, that worked perfectly! Thank you try67!