Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

I need a script to count all text boxes on a form

Avatar

Level 2

I created our organizational chart in Livecycle Designer.  (It doesn't "do" anything; it's just a flat document with no subforms, checkboxes, etc.) 

Each employee's name is in a text box.  The text boxes are all named similarly, starting with the word 'Employee' follwed by the employee's name.  For example, "EmployeeJohnDoe" "EmployeeJaneSmith" etc.

I need to keep a count of our current employees and so I need a script that will count all the text boxes that are named "EmployeeXX."  The answer can go into a text field.

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yes,

The missing dot was my bad.

What do you mean text boxes? If you are referring to Text objects (as opposed to TextField objects), then you would test against a className "draw" and a name "Employee".

Niall

View solution in original post

4 Replies

Avatar

Level 10

Hi,

You would need to do a loop through all the objects in the form, looking for objects with a className "field" and a ui.oneOfChild.className "textEdit". If both conditions are met, then test if the object's name begins with "Employee", if it does add it to the list.

This in the docReady event of the field that displays the number should work

// Declare some variables

var allChildElements;

var intNumElements;

var currentElement;

var i;

var nCounter = "";

// Get all the child nodes of the parent element

allChildElements = form1.nodes;

// Total number of element in the object

intNumElements = allChildElements.length;

// Loop through all the child elements

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

     currentElement = allChildElements.item(i);

     // If the current object is a field then look to see if it is an Employee field

     if (currentElement.className == "field" && currentElementui.oneOfChild.className == "textEdit") {

          // Check to see if the field is an Employee

          if (currentElement.name.substring(0,8) == "Employee") {

               nCounter = nCounter + 1;

          }

     }

}

this.rawValue = nCounter.length;

Hope that helps,

Niall

Avatar

Level 2

Thanks for your quick response!  It almost worked.  I noticed in this line of code...

if (currentElement.className == "field" && currentElementui.oneOfChild.className == "textEdit")

...something looked weird so I put a dot in between 'currentElement' and 'ui'  - - like this: current Element.ui.oneOfChilde.className.....

The other thing is, this script is counting text fields, not the text boxes with the employees' names in them.  Once I fixed that dot issue above, I did an experiment.  I changed the name of my answer text field to 'EmployeeAnswer.'  After I did that, it  showed the number 1.  Well, I knew I only had that one text field on the form so I added another text field, named it 'EmployeeSomething' and, sure enough, the answer changed to 2.

How can I get the script to count just the text boxes, not the text fields?

Thanks again for your help!!!

Avatar

Correct answer by
Level 10

Yes,

The missing dot was my bad.

What do you mean text boxes? If you are referring to Text objects (as opposed to TextField objects), then you would test against a className "draw" and a name "Employee".

Niall

Avatar

Level 2

That did it!  Thank you so much for providing the answers to those of us who know nothing about js.  You have saved the day! Again!