Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Problem getting the # of instances in Numeric Field

Gerben_van_Erke
Level 2
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
Niall_O_Donovan
Correct answer by
Level 10
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
Niall_O_Donovan
Correct answer by
Level 10
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

Gerben_van_Erke
Level 2
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.

Niall_O_Donovan
Level 10
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

Gerben_van_Erke
Level 2
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