Skip to main content
Participant
November 7, 2023
Answered

Add number to even number pages and increment that number on those pages

  • November 7, 2023
  • 1 reply
  • 626 views

Below is the JS that I am using but for some reason it is not incrementing on the fields. All the fields VOUCHERCOUNT values are the same. Attached is a screen shot. I have tired adding the increment both before and after the field being generated. I am trying to add the text fields on the even pages which I was able to do but I need the last part of this text to increment upwards. Any help is much appreciated as this is driving me crazy!! I am not sure if it is just something simple that I am missing.

 

SCHEDULE_NUMBER = this.getField("SCHEDULE_NUMBER").valueAsString;
VOUCHERCOUNT = this.getField("VOUCHERCOUNT").value;

for (var page = 0; page < this.numPages; page++) {

var numb = page+1;
if (numb%2 == 0) {
var firstpagecords = this.getPageBox("Crop",page);
Top = firstpagecords[1];
Midhoriz = firstpagecords[2]/2;
var ScheduleBox = this.addField("Textbox1", "text", page, [Midhoriz-200,Top-2,Midhoriz,Top-24]);
ScheduleBox.value = "L-" + SCHEDULE_NUMBER+ " / " + VOUCHERCOUNT;
ScheduleBox.textSize = 20;
ScheduleBox.textColor = color.red;
ScheduleBox.readonly = true;
VOUCHERCOUNT = VOUCHERCOUNT+1;
}
}

 

This topic has been closed for replies.
Correct answer Nesa Nurani

You're creating fields with same name and those fields will have same value, you need to create fields with unique names: "Textbox1", "Textbox2"...etc, try using this:

SCHEDULE_NUMBER = this.getField("SCHEDULE_NUMBER").valueAsString;
VOUCHERCOUNT = Number(this.getField("VOUCHERCOUNT").valueAsString)+1;
var textFieldCount = 1;

for(var page=0; page<this.numPages; page++){
var numb = page + 1;
if(numb % 2 == 0){
var firstpagecords = this.getPageBox("Crop", page);
Top = firstpagecords[1];
Midhoriz = firstpagecords[2] / 2;

var fieldName = "Textbox" + textFieldCount;
var ScheduleBox = this.addField(fieldName, "text", page, [Midhoriz - 200, Top - 2, Midhoriz, Top - 24]);

ScheduleBox.value = "L-" + SCHEDULE_NUMBER + " / " + VOUCHERCOUNT;
ScheduleBox.textSize = 20;
ScheduleBox.textColor = color.red;
ScheduleBox.readonly = true;

VOUCHERCOUNT++;
textFieldCount++;}}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
November 7, 2023

You're creating fields with same name and those fields will have same value, you need to create fields with unique names: "Textbox1", "Textbox2"...etc, try using this:

SCHEDULE_NUMBER = this.getField("SCHEDULE_NUMBER").valueAsString;
VOUCHERCOUNT = Number(this.getField("VOUCHERCOUNT").valueAsString)+1;
var textFieldCount = 1;

for(var page=0; page<this.numPages; page++){
var numb = page + 1;
if(numb % 2 == 0){
var firstpagecords = this.getPageBox("Crop", page);
Top = firstpagecords[1];
Midhoriz = firstpagecords[2] / 2;

var fieldName = "Textbox" + textFieldCount;
var ScheduleBox = this.addField(fieldName, "text", page, [Midhoriz - 200, Top - 2, Midhoriz, Top - 24]);

ScheduleBox.value = "L-" + SCHEDULE_NUMBER + " / " + VOUCHERCOUNT;
ScheduleBox.textSize = 20;
ScheduleBox.textColor = color.red;
ScheduleBox.readonly = true;

VOUCHERCOUNT++;
textFieldCount++;}}
Participant
November 10, 2023

Great thank you Nesa! Worked perfectly!