Check if row of fields contains blanks before pushing to array?

Explorer ,
Jun 11, 2019 Jun 11, 2019

Copy link to clipboard

Copied

Hi all!

I am trying to build a form where the user can input data into several rows of fields. Once they are done, they can click a button at the bottom of the page which spawns a state form that is filled out with the data from the first page.

The data on the first page is grouped, meaning that I won't necessarily have all the info in consecutive order. For example, I might have Rows 1, 2, 5, and 7 filled out on page one, which need to be translated to Rows 1, 2, 3, and 4 on the spawned page.

I have written a function for this, but I want to add one more feature that I need help with. Right now, the function only works properly if ALL fields in a row have a value. If one of them is blank, it throws off the rest of the sheet. I'm looking for a simple way to check each row for blanks, and assign them a value of " " if the other fields in that row have a value already?

Function below:

function generate()

{

var nIndex = ["1.0", "1.1", "1.2", "1.3", "1.4", "2.0", "2.1", "2.2", "3.0", "3.1", "3.2", "3.3", "4.0", "4.1", "4.2"];

var iIndex = ["DOS", "CTA", "VIN", "CUST"];

var DOSarray = [];

var CTAarray = [];

var VINarray = [];

var CUSTarray = [];

var objArray = [DOSarray, CTAarray, VINarray, CUSTarray];

for (i = 0; i < iIndex.length; i++) {

//iterate through each prefix

for (n = 0; n < nIndex.length; n++) {

//iterate through each field

if (this.getField(iIndex + nIndex).value !== "") {

objArray.push(this.getField(iIndex + nIndex).value);

}

}

for (j=0; j < objArray.length; j++) {

this.getField("MVT_" + iIndex + Number(j + 1)).value = objArray;

}

}

}

I hope that makes sense. Any help would be greatly appreciated!

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

139

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Jun 11, 2019 Jun 11, 2019

Copy link to clipboard

Copied

Your code seems fine... Is it not working? Can you share the file in question?

Likes

translate

Translate

Translate

Report

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
Explorer ,
Jun 11, 2019 Jun 11, 2019

Copy link to clipboard

Copied

It is working, but only if all fields in a particular row have a value.

Each row consists of four fields that need to be moved to the second page. If three of the four are filled out, the rest of the fields after that row are off by one.

Here is the form in question...

Dropbox - TITLE_APP_TRACKER.pdf - Simplify your life

Likes

translate

Translate

Translate

Report

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
Most Valuable Participant ,
Jun 11, 2019 Jun 11, 2019

Copy link to clipboard

Copied

OK, I see what you mean. You need to define at least on value that is required for the row to appear in the summary page and then use it to determine whether or not to include the values of the entire row, even if the rest are blank.

Also, I think you need to reverse the order of your loops. Instead of iterating over the columns and then the rows, you need to go row by row.

Likes

translate

Translate

Translate

Report

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
Explorer ,
Jun 13, 2019 Jun 13, 2019

Copy link to clipboard

Copied

Thank you! You're totally right. I took your advice about reversing the loops, and then it got me thinking in a different way. I renamed all the fields so that they're grouped by row (i.e. ROW1.COL1), then found a handy script that can count the number of children a parent field has.

I rewrote the script so that it checks if any of the child fields have a value for a given row, and even if just one of them does, it pushes the entire row to the array rather than the individual field. Thanks for pushing me in the right direction!

Final script:

function generate() {

var rowNames = ["G1R1", "G1R2", "G1R3", "G1R4", "G1R5", "G2R1", "G2R2", "G2R3", "G3R1", "G3R2", "G3R3", "G3R4", "G4R1", "G4R2", "G4R3"];

var iIndex = ["DOS", "CTA", "VIN", "CUST"];

var rows = [];

for (r = 0; r < rowNames.length; r++) {

var oNames = this.getField(rowNames);

var aNames = oNames.getArray();

var x = 0;

for (i in aNames) {

if (aNames.value) {

x += 1;

}

}

rows.push(x);

}

var DOSarray = [];

var CTAarray = [];

var VINarray = [];

var CUSTarray = [];

var objArray = [DOSarray, CTAarray, VINarray, CUSTarray];

for (n = 0; n < rowNames.length; n++) {

//iterate through each row

for (i = 0; i < iIndex.length; i++) {

//iterate through each prefix

if (rows > 0 ) {

objArray.push(this.getField(rowNames + "." + iIndex).value);

}

for (j = 0; j < objArray.length; j++) {

this.getField("MVT_" + iIndex + Number(j + 1)).value = objArray;

}

}

}

}

Likes

translate

Translate

Translate

Report

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