Skip to main content
Known Participant
Sep 1, 2020 6:01 PM UTC
Answered

adding

Is there any mistake in this script?

I wanted to add few variables in a pdf form, but it is not working: (I am a learner)

 

(this.getField("A").value)*10+ (this.getField("B").value)/3.5+

(this.getField("C").value)*2+

(this.getField("D").value)/2+

(this.getField("E").value)/4+

(this.getField("F").value)/0.227+

(this.getField("G").value)/2+ ((this.getField("H").value)||(this.getField("I").value))+

((this.getField("Text1").value)||(this.getField("Text2").value) ||(this.getField("Text3").value));

 

Thanks,

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Sep 1, 2020 9:04 PM UTC

Using the OR operator in such a calculation is really asking for problems. If they are "interchangable" and only one of them can have a value at any specific point then just add them up. The result of their sum should be the value of the one field that has a value from the group, and it will be much easier to follow and debug.

10 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Sep 1, 2020 9:04 PM UTC

Using the OR operator in such a calculation is really asking for problems. If they are "interchangable" and only one of them can have a value at any specific point then just add them up. The result of their sum should be the value of the one field that has a value from the group, and it will be much easier to follow and debug.

Translate
Known Participant
Sep 4, 2020 11:26 PM UTC

You are right, I just added them.

Thanks

Translate
Nesa Nurani
Community Expert
Community Expert
Sep 1, 2020 8:46 PM UTC

Hi, you can add this before your code: event.value  =

Also you need to add "Number" to your fields like this: Number(this.getField("A").value or with your current code fields J,K,L won't calculate unless there is value in H or I.

Or if you don't know how to do it, just use this code:

var a = Number(this.getField("A").value);
var b = Number(this.getField("B").value);
var c = Number(this.getField("C").value);
var d = Number(this.getField("D").value);
var e = Number(this.getField("E").value);
var f = Number(this.getField("F").value);
var g = Number(this.getField("G").value);
var h = Number(this.getField("H").value);
var i = Number(this.getField("I").value);
var j = Number(this.getField("J").value);
var k = Number(this.getField("K").value);
var l = Number(this.getField("L").value);
event.value = (a*10)+(b/3.5)+(c*2)+(d/2)+(e/4)+(f/.227)+(g/2)+(h||i)+(j||k||l);

Translate
Bernd Alheit
Community Expert
Community Expert
Sep 1, 2020 6:37 PM UTC

You can try the script in the Javascript Debugger.

Translate
Inspiring
Sep 1, 2020 6:09 PM UTC

What are you trying to achive?

Translate
Known Participant
Sep 1, 2020 6:55 PM UTC

just a simple addition with multiplication and division and adding some fields if they are available only (I used OR for that because they are interchangeable).

Translate
Inspiring
Sep 1, 2020 7:12 PM UTC

What is the name of the field where you use this script?

Are all fields values number or are there text also?

 

EDIT: Forgot to ask, what is deciding factor between "I" or "H" and between "Text1" or "Text2" or "Text3"?

Translate