Quantcast
Channel: Adobe Community : All Content - LiveCycle Designer
Viewing all articles
Browse latest Browse all 5571

Sort Array to Remove Null, 0, Empty Values

$
0
0

This dynamic document is 99% done. I have hit a wall on how to prevent null, 0 or empty values from appearing in the BCC list of this page. I have created "if" "else" statements but for some reason they don't filter this null result. Could use a fresh pair of eyes here on a Friday afternoon. Any suggestions on how to prevent the BCC list from populating with the worthless values? Thanks.

 

http://https://workspaces.acrobat.com/?d=sc6DK4bAOK1czwHlBS3E0g

 

Here is the code the Array.prototype came from a StackOver flow thread. I have yet to be able to get this method or another method to even work in Firefox Scratchpad let alone in Livecycle. The array prototype and another Stackoverflow function still allow null values to pass through the function designed to filter them out.

 

 

//fucntion to eliminate duplicates

function eliminateDuplicates(nameArray)

{

  var i,

       len=nameArray.length,

       out=[],

       obj={};

 

  for (i=0; i<len; i++) {

    obj[nameArray[i]]=0;

  }

  for (i in obj) {

    out.push(i);

  }

   

   return out;

 

};

 

function cleanArray(sortedNames){

  var celeryArray = new Array();

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

      if (sortedNames[i])

      {

       celeryArray.push(sortedNames[i]);

      }

                                           }

  console.println("celeryArray = " + celeryArray);

  return celeryArray;

 

}

 

//Count rows

var rows = resolveNodes("form1.Page1.Document.OnethruTen.OneThruFour.Four[*]"); //count the rows

var nRows = rows.length-1; //assign row count to variable

 

// Create new array to hold sorted array data[][][]...

var nameArray = new Array ();

 

//Loop through the number of #4 subform instances obtaining values for each textfield

for ( i=0; i<= nRows; i++)

{

    //Fill array with values from #4 subform

    nameArray[(i*4)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Owner.rawValue;

    nameArray[((i*4)+1)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").DF.rawValue;

    nameArray[((i*4)+2)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Mgr.rawValue;

    nameArray[((i*4)+3)] = xfa.resolveNode("form1.Page1.Document.OnethruTen.OneThruFour.Four["+ i +"]").Exec.rawValue;

}

//console.println(nameArray);

 

//[][][][][][].........

sortedNames = new Array();

 

//[0 Thomas, Snyder T][1 Bollings, Temera A][2 Kiomer, Ioda L][3 Berry, Steve J] [5....

var sortedNames = eliminateDuplicates(nameArray);

console.println("sortedNames =" + sortedNames);

 

 

var sortedClean = cleanArray(sortedNames)

console.println("sortedClean = " + sortedClean);

 

 

//Number of values in the sortedNames array

var nsortedValues = sortedNames.length;

console.println("nsortedValues =" + nsortedValues);

 

//Number of Rows to add to BCC list

var nccRows = Math.ceil((nsortedValues/2));

console.println("nccRows = " + nccRows);

 

//Variable to add number of rows in addInstance script below

var nBCCaddRows = (nccRows-2);

console.println("nBCCaddRows = " + nBCCaddRows);

 

if ( nBCCaddRows > 0 )

{

    for(i=1; i <= nBCCaddRows; i++)

        {

            this.resolveNode('form1.Page1.ActionOwner.Table1._Name[1]').addInstan ce(1);

                if (xfa.host.version < 8) {

                                            xfa.form.recalculate(1);   

                                          }                                           

        }

}

 

 

//Loop through the values of the array and place them in the BCC list

for ( i=1; i <= nccRows; i++)

{                               

               if ( sortedNames[((i*2)-2)] !=0 )                                                           

               {

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField1. rawValue = sortedNames[((i*2)-2)];  //always even i=1 sortedNames[0]  i=2 sortedNames[2]

               }

              

               else

               {

               form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField1. rawValue = " ";

               }

              

               if ( sortedNames[((i*2)-1)] != 0)

               {

    form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField2. rawValue = sortedNames[((i*2)-1)]; //i=1 sortedNames[1]  i=2 sortedNames[3]

               }

              

               else

               {

               form1.Page1.ActionOwner.Table1.resolveNode("Name["+i+"]").TextField2. rawValue = " ";

               }

}


Viewing all articles
Browse latest Browse all 5571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>