Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Remotely add and remove Instances from different pages

Avatar

Level 2

Similar to my other post, I have a form that has multiple pages, one being a calculator (OA_CALC) that shows every variable for calculation; the second (OA_PG1), customer facing showing only pertinent information. So both tables should add/remove and show the data being contolled from OA_CALC. I am able to addInstance and source the date to both pages, but for some reason removeInstance only works on the page where the button exists. So rows on OA_PG1 never delete, please advise.

On OA_CALC i have an ADD ROW button with the following code:

form1.OA_CALC.Table1.HeaderRow.#subform[0].AddRow::click - (JavaScript, client)

OA_CALC.Table1.RowItems.instanceManager.addInstance(1);

OA_PG1.ProjectSavingsGROUP.Table1.RowItems.instanceManager.addInstance(1);

and a DELETE ROW with the following code:

form1.OA_CALC.Table1.RowItems.#subform[0].DelRow::click - (JavaScript, client)

var vIndex = this.parent.parent.index;

OA_CALC.Table1.RowItems.instanceManager.removeInstance(vIndex);

OA_PG1.ProjectSavingsGROUP.Table1.RowItems.instanceManager.removeInstance(vIndex);

One thing that I tried was creating buttons on OA_PG1 with the code specific to that table, that seemed to work. So I know the syntax works, but cannot figure out how to control it from a different page. Please help.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

I have an example here that demonstrates this behaviour: http://assure.ly/eTOXaH.

Hope that helps,

Niall

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Hi,

I have an example here that demonstrates this behaviour: http://assure.ly/eTOXaH.

Hope that helps,

Niall

Avatar

Level 2

Oh wow. That is perfect. I was so close

Thank you.

Avatar

Level 2

urgh, apparently I am still very close. I have used your sample, but it seems that the execEvent("click") is not working correctly or my syntax is wrong somewhere. Where am I going wrong?

Button Code on first table:

form1.OA_CALC.Table1.RowItems.deleteBtn::click - (JavaScript, client)

var vCurrentRow = this.parent.index;

OA_CALC.Table1._RowItems.removeInstance(vCurrentRow);

xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]").deleteBtn.execEvent("click");

Invisible Button Code on second table:

form1.OA_PG1.ProjectSavingsGROUP.Table1.RowItems.deleteBtn::click - (JavaScript, client)

OA_PG1.ProjectSavingsGROUP.Table1._RowItems.removeInstance(this.parent.index);

Edit: Here is the Console report from the Acrobat JavaScript Debugger:

xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]") is null

7:XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:clickException in line 7 of function top_level, script XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:click

TypeError: xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]") is null

7:XFA:form1[0]:OA_CALC[0]:Table1[0]:RowItems[1]:deleteBtn[0]:click

Avatar

Level 10

Hi,

I'm gone now, but check the JavaScript Console for errors. Press Control+J when previewing the form in LC Designer or opened in Acrobat.

Niall

Avatar

Level 2

figured it out.

The code failed because I had put delete local row buttton BEFORE calling the delete remote row button. I believe this stopped the code from fully exectuing since it's instance was removed mid-code. This now matches Niall's provided example.

Bad Code:

form1.OA_CALC.Table1.RowItems.deleteBtn::click - (JavaScript, client)

var vCurrentRow = this.parent.index;

OA_CALC.Table1._RowItems.removeInstance(vCurrentRow);

xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]").deleteBtn.execEvent("click");

Good Code:

form1.OA_CALC.Table1.RowItems.deleteBtn::click - (JavaScript, client)

var vCurrentRow = this.parent.index;

xfa.resolveNode("OA_PG1.ProjectSavingsGROUP.Table1.RowItems[" + vCurrentRow + "]").deleteBtn.execEvent("click");

OA_CALC.Table1._RowItems.removeInstance(vCurrentRow);

Woohoo!