Question on FormCalc

Avatar

Avatar

Giantsnation

Avatar

Giantsnation

Giantsnation

16-12-2010

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")

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Avatar

radzmar

MVP

radzmar
MVP

16-12-2010

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.")

Answers (7)

Answers (7)

Avatar

Avatar

radzmar

MVP

Avatar

radzmar

MVP

radzmar
MVP

20-06-2016

I believe this thread is about the same question … Below Code works great but counter still shows 1 even there is no empty filled

Avatar

Avatar

mattiaswallin

Avatar

mattiaswallin

mattiaswallin

16-06-2016

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

Avatar

mattiaswallin

Avatar

mattiaswallin

mattiaswallin

15-06-2016

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

Avatar

pguerett

Avatar

pguerett

pguerett

16-12-2010

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

Avatar

Karwan_Mawlood

Avatar

Karwan_Mawlood

Karwan_Mawlood

16-06-2016

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.

Avatar

Avatar

Karwan_Mawlood

Avatar

Karwan_Mawlood

Karwan_Mawlood

16-06-2016

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

Avatar

Karwan_Mawlood

Avatar

Karwan_Mawlood

Karwan_Mawlood

15-06-2016

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 ?