Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How do i increment the instance manager?

Avatar

Level 7

Hi,

I have created a flowed form with a subform (sf). I have automatic numbering in a numeric field in sf that is based on the instanceManager count. Hence, if i create a new subform the subform's numeric field increments based on the count.

The problem i have is is quite logical but i cant solve it:

If I add 3 subforms (they will be numbered 1, 2 & 3 in the numeric field) and then remove the subform with number 2, the number of instances will be 2. If i add a new subform, the numeric field will get the number 3 which already exists. I had 3 subforms, removed one and then added one...still 3 subforms.

Reordering the numbers is a bit beyond me at the moment, but what I would like to do is "fake" the count so that the instance number effectively wont change so if I remove number 2, the count will still be 3 and the new subform will be number 4.

I have tried this code on my remove button and nothing works:

sf.instanceManager.count + 1;

sf.parent.index + 1;

sf.setInstance(sf.instanceManager.count + 1);

Any ideas? I am using ES2

1 Accepted Solution

Avatar

Correct answer by
Level 10

Actually the code above might not do exactly what you want... as it will not count the removed instances...

What you could do, add a hidden field that will increment each time an instance is added to the subform 'sf', and use this hidden field to display the number wanted in the new instances

View solution in original post

6 Replies

Avatar

Level 10

Hi there,

instead of having the field to be calculated automatically, you should just insert the code within the initialize event of the field like the following :

Hope this will help!

Avatar

Correct answer by
Level 10

Actually the code above might not do exactly what you want... as it will not count the removed instances...

What you could do, add a hidden field that will increment each time an instance is added to the subform 'sf', and use this hidden field to display the number wanted in the new instances

Avatar

Level 7

Great idea, thanks I will try it out

Avatar

Level 7

I can make this work with the hidden fields. Thanks

If i was wanting to reorder the number manually, how do i refer to a second or third instance when the form is running?

Example:

I have three subform instances (sf1, sf2 & sf3) and on the subform there is a numericfield called nf1.

How do i refer to nf1 on the third instance since they all have the same name?

Sf3 is just another instance of the main subform.

Keeping track of how many subforms were created would enable me to backtrack and renumber other forms using the code.

Avatar

Level 10

To be able to access an instance of a specific subform, you need to use the resolveNode() method

if you already know which instance you want to access, you can use the index wanted to access it otherwise, use a for loop

Here is how to use resolveNode :

within a for loop it would look something like this :

Hope this will help you also!