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

Repeating Subform

Imgoodtogo
Level 2
Level 2

Hello,

On my form I have a "Claimant" section. When you click a button, you can add a new claimant.

On different button, various subforms are repeated as well as a subform in the "Claimant" section.

What I need this button to do is also have the subform that is repeated in the "Claimant" section also to repeat for the new claimant.

The script to add a new claimant is simply:

form1.Container.Claimant.instanceManager.addInstance(1);

The script on the other button is this:

addRemSub.instanceManager.insertInstance(0,1);

Container.ClaimSummary.instanceManager.insertInstance(0,1);

----Container.Claimant.InjuryStatus2.InjDiff.instanceManager.insertInstance(0,1)

Container.MCTable.instanceManager.insertInstance(0,1);

Container.FMRPTable.instanceManager.insertInstance(0,1);

Container.addRemSub.CommitteeDetails.instanceManager.insertInstance(0,1);

The line where I have inserted the ---- is the part that I also need when a new claimant is added.

Can anyone help?

Thanks in advance.

5 Replies
Magus069
Level 10
Level 10

Hi there,

Not quite sure what you are trying to do here, except adding instances to other subforms...

I want to make sure that you are aware that insertInstance method is to add an instance at the index specified, you don't really need to specify the Boolean value as parameter for insertInstance method

Right now each instertInstance methods in the other button is to add an instance at the first position of the subform's list, because you specify 0 as the index parameter.

And the addInstance method in the add new claimant button, is adding an instance at the end of the subform's list

So if you need a subform to be added when you add a new claimant, and your goal is to add that instance at the same position than your claimant's position, make sure to use the same method (addInstance or insertInstance)

if you are using insertInstance, make sure both subforms insert an instance at the right position with the index specified as the parameter

I hope this will help!

Imgoodtogo
Level 2
Level 2

Yes that is correct.

I want the new instance to be in the first position when using the second button ("new month") but when a new claimant is added, it will be added following the first claimant.

So when there is more than one claimant and a "new month" is clicked, I need the subform InjDiff to be inserted for all claimants whether there is one or 5.

I think I have to loop through the claimant subform and then insert in InjDiff subform but I am not sure of how to write this.

I hope this clarifies what I'm asking and hope you can help.

Thanks

Magus069
Level 10
Level 10

Hi again,

I hope I can help too,

If I understand well, you want to set the number of instances of InjDiff to the number of instances of Claimants when the "new month" button is clicked... right?

If so,

you can use the method setInstances instead of using insertInstance, which will set the number of instances automatically to the number sent in parameter to the method.

So it should look something like the following :

But this will only set instances to one InjDiff subform.. if what you want is to set the instances of InjDiff within each Claimant's subforms, then you will need to loop through each Claimant's subform, like the following

I hope this will help ya!

Imgoodtogo
Level 2
Level 2

Hello and thanks for the reply.

I try adding your code to my "add month" button but needless to say it didn't work as I very likely did something wrong.

This is what I had:

addRemSub.instanceManager.insertInstance(0,1);

Container.ClaimSummary.instanceManager.insertInstance(0,1);

//Container.Claimant.InjuryStatus2.InjDiff.instanceManager.insertInstance(0,1);

Container.MCTable.instanceManager.insertInstance(0,1);

Container.FMRPTable.instanceManager.insertInstance(0,1);

Container.addRemSub.CommitteeDetails.instanceManager.insertInstance(0,1);

for(var i = 0, oLen = Container.Claimant.instanceManager.count; i < oLen; i++){

    Container.resolveNode("Claimant[" + i.toString() + "]").InjuryStatus2.InjDiff.instanceManager.setInstances(oLen);

    }

I did not change anything on the "add claimant" button as the way it was working was fine.

I'm really not great at Javascript so I really appreciate your help.

Thanks!

Magus069
Level 10
Level 10

If you look at any errors shown in the debugger window (Ctrl + J)

is there any error message? That would greatly help for debugging the code