How to get the name of a subform in a script?

Beachbum2015

17-03-2015

I have a script that I'd like to use to count how many checkboxes are checked in a particular subform.  Problem is that I have several subforms with checkboxes, and I only want to evaluate checkboxes in a certain subform.  The following script works, but again, looks at all checkboxes on the entire form.

What if statement would I need if I wanted to limit the function to only work on the subform named Employee_Info?  I just can't figure out how to specify a subform name and compare it to the subform name of each checkbox.  I hope that makes sense.

function countChk(vNode) {

          if (vNode.className === "field") {

                    if (vNode.ui.oneOfChild.className === "checkButton") {

                              if (vNode.items.nodes.length > 1) {

                                        if (vNode.value.oneOfChild.value == 1) {

                                                  nChk++ ;

                                        }

                                }

                            }

                        }

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

        countChk(vNode.nodes.item(i));

          }

}

Accepted Solutions (0)

Answers (3)

Answers (3)

Magus069

MVP

18-03-2015

Hi there,

the name property would be the correct attribute to get the subform name, just by looking at the code it doesn't seem like it's doing the right thing

I am assuming that you send Main in the function countChk() which would look something like this

And you probably want to make sure you are entering the right subform so you need to keep that loop at the end of the function

but if you want to get through all the checkboxes inside that subform you must do a loop through that node to find each checkbox

I am assuming that the function would probably look something like this

Hope this help!

Beachbum2015

18-03-2015

Hi Magus069,

No luck adding the last if statement shown above.  Actually, the subform name is Door_Subform, which I changed, and it looks like the derived subform name is not matching what is specified.  I have an if statement not shown above that evaluates if nChk is < 3, then display an error message.  When I check off more than three boxes, I still get the error that not enough boxes have been checked.  So it seems that vNode.nodes.item(i).name may not be grabbing the correct attribute (subform name).

Here's the hierarchy to the subform in question.

     form1.Main.Door_Subform