Skip to main content
Alliosaaa
Inspiring
June 11, 2019
Question

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

  • June 11, 2019
  • 1 reply
  • 715 views

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!

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
June 11, 2019

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

Alliosaaa
AlliosaaaAuthor
Inspiring
June 11, 2019

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

try67
Community Expert
Community Expert
June 11, 2019

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.