Expand my Community achievements bar.

Exits a for loop when encountered a null value

Avatar

Level 1

Hi,

I've encountered this problem wherein I need to loop through all the fields and determine if its a text field, then check whether the field is null or not.However if it encountered a text field with a null value, it exits the loop and the rest of the text fields are not checked. Any ideas?  Please see the code below. Thanks!

for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++)
    {
      var oFields = xfa.layout.pageContent(nPageCount, "field");
      var nNodesLength = oFields.length;

      for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++)
         { 
                 if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit")
                   { 
                        app.alert(oFields.item(nNodeCount).name);
                        if (fieldObject.rawValue!=null) 
                          {
                           app.alert(fieldObject.rawvalue);
                          }
                        else
                          {
                           fieldObject.fillColor = "255,0,0";   // once this line is executed it exits the loop
                          } 
                   }
           }
      }

1 Reply

Avatar

Level 1

I  figured it out, Its not actually exiting the loop but stops at a certain line because the variable at that line is not yet declared

for (var nPageCount = 0; nPageCount < xfa.host.numPages; nPageCount++)
    {
      var oFields = xfa.layout.pageContent(nPageCount, "field");
      var nNodesLength = oFields.length;

      for (var nNodeCount = 0; nNodeCount < nNodesLength; nNodeCount++)
         { 
                 if (oFields.item(nNodeCount).ui.oneOfChild.className == "textEdit")
                   { 
                        app.alert(oFields.item(nNodeCount).name);
                        if (fieldObject.rawValue!=null) 
                          {
                           app.alert(fieldObject.rawvalue);
                          }
                        else
                          {
                           fieldObject.fillColor = "255,0,0";   // once this line is executed it exits the loop

                           errcnt++;   //errcnt is not declared
                          } 
                   }
           }
      }