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

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

New Here ,
Nov 06, 2023 Nov 06, 2023

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.

 

image001 (1).png

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;
}
}

 

TOPICS
JavaScript , PDF
643
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
1 ACCEPTED SOLUTION
Community Expert ,
Nov 06, 2023 Nov 06, 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++;}}

View solution in original post

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 ,
Nov 06, 2023 Nov 06, 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++;}}
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 ,
Nov 10, 2023 Nov 10, 2023
LATEST

Great thank you Nesa! Worked perfectly!

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