Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating an Invoice with If, Then, Else

New Here ,
Jan 18, 2022 Jan 18, 2022

Total newb to javascript, so pardon my ignorance, but your help would be so much appreciated.

I want to create an invoice with Fields A, B, and C.

What I want C to do:
If A*B is >1 and <50, then C = 50

If A is blank or =0, then C is blank.

Also, would I put the script in the Custom calculation script or Custom Validation Script or elsewhere?
Thank you.

TOPICS
How to , JavaScript , PDF forms
432
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 19, 2022 Jan 19, 2022

What happen if result is not between 1 and 50?

Use script as custom calculation script of field C:

var a = Number(this.getField("A").value);
var b = Number(this.getField("B").value);
var x = a*b;
if(x>1 && x<50)
event.value = 50;
else if(a == "")
event.value = "";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2022 Jan 19, 2022

Thank you so much for your answer. I will give it a try when I have more time later today.

If the result is >50, then the result is A*B.

So what I'm wanting to do is apply a minium fee if the total does not meet a specific amount. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 19, 2022 Jan 19, 2022
LATEST

Sorry, to clarify, if A*B is >50, then display the actual result of A*B. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines