Expand my Community achievements bar.

SOLVED

Problem getting the # of instances in Numeric Field

Avatar

Level 2

Hi there,

I've created a form on which a user can add / duplicate the subform.  That subform is located in another subform.
SO the hierarchy is like:

Subform 1

     Subform 2

          Table with fields

     Delete button

Add button

Numeric Field

The numeric field has to display the number of instances of Subform 2.

I selected the field and added the code:

Subform2.instancaManager.count;

But that doesn't work at all. The field doesn't display anything.

The subform has a minimal count of 1. So in my logic it should display 1. But I ain't a scripter at all...so frankly I must think of it in a wrong way.

Can someone help me get this numeric field to calculate the subform2 instances? In dummy language please :-)

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Since the numeric field is outside Subform1, you have not provided a full enought reference from the numeric field to Subform2. See here for a description: http://assure.ly/kUP02y.

This should work in the calculate event of the numeric field:

this.rawValue = Subform1.Subform2.instanceManager.count;

If the subform did not have a minimum count, then you would use the underscore shortcut for instanceManager _:

this.rawValue = Subform1._Subform2.count;

Both options are JavaScript. I prefer using the _ shortcut everytime I am working with repeating instances. 

Hope that helps,

Niall

View solution in original post

4 Replies

Avatar

Correct answer by
Level 10

Hi,

Since the numeric field is outside Subform1, you have not provided a full enought reference from the numeric field to Subform2. See here for a description: http://assure.ly/kUP02y.

This should work in the calculate event of the numeric field:

this.rawValue = Subform1.Subform2.instanceManager.count;

If the subform did not have a minimum count, then you would use the underscore shortcut for instanceManager _:

this.rawValue = Subform1._Subform2.count;

Both options are JavaScript. I prefer using the _ shortcut everytime I am working with repeating instances. 

Hope that helps,

Niall

Avatar

Level 2

Thanks, that was it. Although I renamed the form to SubForm-data...it seems the - was creating problems with counting. Removing the - made it work.

Avatar

Level 10

Yes, the minus sign should not be used in object names, as it is taken literally as minus and the script fails.

Camel-case is useful for naming objects: eg SubformData.

Good luck,

Niall

Avatar

Level 2

Thanks again! I'll keep that in mind :-).
Thanks for wishing me good luck, going to need it...already running into another problem with pagination. But that's for another discussion if I can't find it through searching