Skip to main content
Participating Frequently
January 18, 2023
Question

Making a basic invoice pdf and cannot get my total field to set the value right.

  • January 18, 2023
  • 2 replies
  • 860 views

var total
{
for(i2 = 0; i2 < 18; i2++)// Itteration through Lines
{
var itemVolume = String(this.getField('105' + 'Qu' + i2).valueAsString); // Declares Item volume variable and targets each lines volume field
if(itemVolume > 0)// Checks for values of 1 or greater
console.println(itemVolume)
{
total + (this.getField('105' + 'Pri' + i2)).valueAsString;
this.getField("105Total").valueAsString = total
}
}
}

 

 

 

My Field names are 105PriX and 105QuX  X being 0-18 It is currently just setting my total field to the word [Object Field] if im not mistaken i should be solving that with .valueAsString? Would appreciate any and all help thank you very much!

This topic has been closed for replies.

2 replies

Bernd Alheit
Community Expert
January 18, 2023

Try this:

total = total + Number(this.getField('105' + 'Pri' + i2).valueAsString);
Participating Frequently
January 18, 2023

Awesome thank you very much solved one problem only thing is now it keeps building up the total variable every time i run the program Would it be better to set total to 0 outside of the loop so it resets once it finishes my for loop?  Or would it be better to have a clear button that sets total to 0? Sorry started this project months ago so a little rusty on js thanks for the help!

Bernd Alheit
Community Expert
January 18, 2023

For the loop use:

var total = 0;

Bernd Alheit
Community Expert
January 18, 2023

You doesn't you set any value for total.

Participating Frequently
January 18, 2023

Total is being set based off the values of (this.getField('105' + 'Pri' + i2) do i need to set it to 0 to start with?