Expand my Community achievements bar.

SOLVED

Question on FormCalc

Avatar

Level 2

Not sure what functionality I need to be using but here is what I am looking to accomplish. I need to know how to count the number of rows in a table that are not  null. I have a table with data but what I need to know is how many rows  are filled out. In other words, if 5 rows out of 20 are filled out, I  need my form to tell me that 5 rows are filled in. The specific data in  the table is irrelevant for this calculation. Furthermore, I do not need the formula to validate the all columns in the row, just 1 column filled out is fine.


I tried the following formula but this is literally counting each row as  1 without looking for data. If the row is blank, I need the formula to  skip that (or count it as 0). As mentioned, I can also pinpoint a specific cell if  needed.

Count("Page2.Table1.Row1", "Page2.Table1.Row2")

1 Accepted Solution

Avatar

Correct answer by
Level 10

You also can do this in FormCalc.

The syntax is similar to JavaScript.

var FilledRows = 0

for i = 0 upto Row.instanceManager.count -1 do

     if (Row[i].Name ne null) then

          FilledRows = FilledRows + 1

     endif

endfor

; Popup message with number of filled rows

xfa.host.messageBox(Concat("There are currently", FilledRows, " filled rows in the table.")

View solution in original post

8 Replies

Avatar

Former Community Member

I woudl do this using Javascript and not FormCalc. You will need to loop through each of the rows and test a field to see if it is populated.

You can use the RowName.instanceManager.count to get the number of Rows in your table. Then you can use that to control a For loop to lok at each row.

Lets assume your Row is called Row and the field you want to test is called Name. Each field will have a uniques name as Row[instanceMumber].Name

So your code woudl be something like this:

var NoOfRows = 0;

for (i=0;i<Row.instanceManager.count;i++){

   if (xfa.resolveNode("Row[" + i + "]").Name.rawValue != null){

     NoOfRows = NoOfRows + 1;

   }   

}

When this code is run it the NoOfRows variable will contain the number of rows that have a value in it.

Hope that helps

Paul

Avatar

Correct answer by
Level 10

You also can do this in FormCalc.

The syntax is similar to JavaScript.

var FilledRows = 0

for i = 0 upto Row.instanceManager.count -1 do

     if (Row[i].Name ne null) then

          FilledRows = FilledRows + 1

     endif

endfor

; Popup message with number of filled rows

xfa.host.messageBox(Concat("There are currently", FilledRows, " filled rows in the table.")

Avatar

Level 3

you code is amazing works like a charm, but how to make it check for all the rows and if there is no empty row then execute save as ?

Avatar

Level 3

Just make an if statement below that and check if the "empty counter" is zero.

if (FilledRows == 0){

     app.execMenuItem("SaveAs");

}

This is javascript I believe though, not very experienced in using FormCalc, but should be something alike.

Avatar

Level 3

Thanks alot dear

your idea works great, but I don't know what is wrong it's still showing that there is 1 empty fielled in the form while there is none ! Help please below is my code :

Below is the code to get the empty filleds (counter);

form1.Page1.notification.NumericField1::ready:layout - (FormCalc, client)

var FilledRows = 0

for i = 0 upto Body.Table1.Row1.instanceManager.count - 1 do

     if (Body.Table1.Row1[i].drp_names eq null) then

          FilledRows = FilledRows + 1;

          this.rawValue = FilledRows;

     endif

endfor

the code in Javascript to check if the value of the counter is zero

form1.Page1.save_as::click - (JavaScript, client)

   if (notification.NumericField1.rawValue == 0){

  xfa.host.messageBox("This will save your form as PDF form, means you can edit later once more","Save As Form",3,0);

  app.execMenuItem("SaveAs");}

else

{xfa.host.messageBox("You have : " + notification.NumericField1.rawValue + " empty highlighted fields","Empty Fields",3,0);}

Avatar

Level 3

Just as a disclaimer, I havent run this code at all personally, so I would suggest you to use some textfield/messageBox to "verify" that the counter is working correctly. At first I misinterpreted your if statement in the counter as to be honest now you are counting "NotFilledRows" and not "FilledRows" as your variable is named .

Anyhow, from what I can see the code would work as inteded. But I havent ever used this ".drp_names" that you are using? Have you tried the ".Name" as Radzmar is using above?

And otherwise I would suggest you to double check your counter in some example environment, to really make sure that that code works, one example could be to leave out 2 entries in the table empty, does it show up as two empty fields etc.?

Avatar

Level 3

first of all thanks for giving your time to my case, however the (drp_names) is text field and yes it shows that there is 2 empty fields but when there is not empty fields the counter does not reach to zero it stays at 1 this is my problem.