Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Delete a row from a different subform

Avatar

Level 6

I have two subforms (SUB1 & SUB2) with a repeating row (Container) for each data item . A new "Container" row is added to each Subform via an Add row button. NOTE: When the button is pressed, both subforms receive an additional row:

SUB1._Container.addInstance();

SUB2._Container.addInstance();

Currently, the form is setup to auto-copy data from certain fields  in the Container row of SUB1 into the Container row of SUB 2, and all is working fine. What I'm looking for is...whenever I delete a row from SUB1 ( via _Container.removeInstance(this.parent.index); ), I'd like that the same "index" row to be deleted from SUB2. So if instance 3 is deleted from SUB1, I'd like instance 3 to be deleted from SUB2.

Any suggestions?

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Well if you're button with the script is in Sub1 and you delete Sub1 instance at first you will not be able to end the script, you should delete the sub2 before deleting sub1 if the removeInstance is in Sub1

If the action script is in Sub2, write your code like this

SUB1._Container.removeInstance(this.parent.index);

SUB2._Container.removeInstance(this.parent.index);

If the action script is in Sub1, write your code like this

SUB2._Container.removeInstance(this.parent.index);

SUB1._Container.removeInstance(this.parent.index);

View solution in original post

5 Replies

Avatar

Level 10

If both Sub1 and Sub2 are created along together, each index should refer to the index of the other subform.

So if your index specified is 3 for Sub1, and you want to delete the same one for Sub2, just need to write the same line as for Sub1

SUB1._Container.removeInstance(this.parent.index);

SUB2._Container.removeInstance(this.parent.index);

Avatar

Level 6

Tried that initially; it only deletes the subforms (_Containers) from SUB1 not SUB2

Avatar

Level 6

oddly enough...if I comment out the first line SUB1._Container.removeInstance(this.parent.index);  it deletes the correct index/instance from the second group (SUB2). But if I keep both lines intact, it only removes from the first group (SUB1).

As I think about what may be going on, it makes perfect sense. If both scripts are left intact...once it performs the first delete from SUB 1 the index value no longer exist, thus the reference for the second delete is broken.  Meaning, if instance/index 2 is deleted from SUB1, and the next script references the index of 2 (which no longer exists) it doesn't know what to delete.

That's my theory, so perhaps I need a way to store the index value so the second script can use it to delete the same instance/index in SUB2.

Avatar

Correct answer by
Level 10

Well if you're button with the script is in Sub1 and you delete Sub1 instance at first you will not be able to end the script, you should delete the sub2 before deleting sub1 if the removeInstance is in Sub1

If the action script is in Sub2, write your code like this

SUB1._Container.removeInstance(this.parent.index);

SUB2._Container.removeInstance(this.parent.index);

If the action script is in Sub1, write your code like this

SUB2._Container.removeInstance(this.parent.index);

SUB1._Container.removeInstance(this.parent.index);

Avatar

Level 6

Correct..I tried that after my last post and it worked by simply switching the order of the scripts.

Funny how the simple things in life are often made complex.

Thanks for your follow up and assistance.