Expand my Community achievements bar.

SOLVED

Getting error when adding or removing instance of a table row

Avatar

Former Community Member

I'm absolutely brand-new to LiveCycle ES2 (we were using Adobe Pro 7 up until a week ago). I've been playing around with some of our forms to try and see what LiveCycle can do to update these into a better format.

I have a table with a header row, a body row, and a footer row. The body row needs to be repeatable. I used the Custom object "Subform Instance Controls: Insert Remove Move" to add the plus and minus signs. I set the Action to repeat or remove the instance of that one row.

The entire table is wrapped in a subform that is set to flowed. The row that needs repeating is set to "Repeat Row for Each Data Item" with Min Count set at 1 and no Max Count set. The entire document is also wrapped in a subform set to flowed.

When I go into Preview and use the Add an Instance button, I get this error:

"Warning: JavaScript Window - Insert Item.

You have reached the maximum number of items allowed."

If I try the Remove an Instance button, I get a similar error about the minimum number of items allowed.

BUT (and here is the confusing part) the buttons work! The row gets added or deleted, it just gives me the error first. What could be going on? I've tried setting the Max Count to 20 to see if giving it a max count would help, but I still get the error.

I've done all this using Design View, because I know nothing about JavaScript, but I can post the generated code, if it helps.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hmm ok, the Action Builder script is very overloaded, not sure what causes the error.

My suggestion:

1. Remove all actions you created with the action builder

2. For the Add button use this JavaScript in the click event

3.For the Remove button this JavaScript (will remove always the last instance of the row)

View solution in original post

7 Replies

Avatar

Level 10

Hi,

Where are the buttons located relative to the repeatable row?

What does the script looks like you use?

If possible share your form on Acrobat.com or any other file hoster.

It will be easier for us to analyse your problem.

Avatar

Former Community Member

Here's a link to the document as it is now: http://temp-share.com/show/gFHKd2x6Y

The buttons are located above the header row of the table. Here's the hierarchy:

Tablesubform (flowed)

     Button subform (positioned)

          Insertsubformbutton

          Removesubformbutton

     Table

          Header

               (four cells included under table)

          TableRow - this is the one I want repeatable

               (four cells included)

          Totalmiles (this is a footer row for calculating a summary, includes 2 cells)

          mileagecost (another footer row for another calculation, two cells)

         

Each row is set to "repeat row for each data item" with min count set at 1, no max count. I've tried deselecting the "repeat row" option for all but the row I want repeating, but it makes no difference.

The button actions are set as following:

When button InsertSubformButton1 is clicked, Add a new instance of TableRow

When button RemoveSubformButton1 is clicked, Remove TableRow last instance

The code is below. Because I don't know anything about Javascript (again, just using Designer view right now), I'm not sure if I'm posting the correct code, but I tried to include what looks like the code surrounding the table and actions.

<subform w="203.201mm" layout="tb" name="tablesubform">

            <subform w="12.7mm" h="10.795mm" name="buttonsubform">

               <bind match="none"/>

               <margin leftInset="1.27mm" topInset="1.27mm" rightInset="1.27mm" bottomInset="1.27mm"/>

               <field h="5.08mm" name="InsertSubformButton1" w="5.08mm" y="3.175mm">

                  <ui>

                     <button/>

                  </ui>

                  <font typeface="Arial"/>

                  <caption>

                     <value>

                        <text>+</text>

                     </value>

                     <para hAlign="center" vAlign="middle"/>

                  </caption>

                  <border hand="right">

                     <?templateDesigner StyleID apbx2?>

                     <edge stroke="raised"/>

                     <fill>

                        <color value="212,208,200"/>

                     </fill>

                     <corner/>

                  </border>

                  <bind match="none"/>

                  <event name="event__click" activity="click">

                     <script contentType="application/x-javascript">//+ GENERATED - DO NOT EDIT (ID:1BFDBD23-1B94-4391-AE50-13B838C6994A CRC:854927680)

//+ Type: Action

//+ Result1: AddInstance("$Node2")

//+ Node2: form1[0].pagesubform[0].tablesubform[0].Table[0].TableRow[0]

//+ Node1: form1[0].pagesubform[0].tablesubform[0].buttonsubform[0].InsertSubformButton1[0]

//+ Condition1: Button("$Node1","click")

//+ ActionName: InsertSubformButton1.click

this.resolveNode('Table._TableRow').addInstance(1);

if (xfa.host.version &lt; 8) {

          xfa.form.recalculate(1);

}

//-

/*

   This button will insert one instance of the repeating subform or table row.

   bCalc: Flag - true if the new instance might be referenced by other calculations, otherwise false.

   message: The error message displayed.

*/

var bCalc = true;

var message = "You have reached the maximum number of items allowed.";

// DO NOT MODIFY THE CODE BEYOND THIS POINT - 9.0.0.2.20101008.1.734229.723806 - Subform_Instance_Controls_IRM.xfo.p2

var oWrapper = this.parent.parent;          // The outer subform built in to the object, enclosing the button group.

var oTargetSubform = oWrapper.parent;          // The subform or table row the controls are intended to manipulate.

var oManager = oTargetSubform.instanceManager; // Get the instance manager.

var nMaxCount = oManager.occur.max;                     // Get the maximum number of subform occurrences allowed.

var nSubCount = oManager.count;                              // Get the current number of instances.

// Proceed if the maximum number of subform occurrences has not been reached.

if ((nMaxCount == "-1") || (nSubCount &lt; nMaxCount)) {

 

          // Invoke the Instance Manager.

          var oNewInstance = oManager.addInstance(1);

          // Fire the form calculations.

          if (bCalc == true) {

                    // Execute all the form calculations.

                    xfa.form.recalculate(1);

          }

          // Move the new subform below the current one.

          var nIndexFrom = oNewInstance.index;

          var nIndexTo = oTargetSubform.index + 1;

          oManager.moveInstance(nIndexFrom, nIndexTo);

} else {

          xfa.host.messageBox(message,"Insert Item", 3);

}

// END OF DO NOT MODIFY

</script>

                  </event>

                  <assist>

                     <toolTip>Insert an item</toolTip>

                  </assist>

               </field>

               <field h="5.08mm" name="RemoveSubformButton1" w="5.08mm" x="5.08mm" y="3.175mm">

                  <ui>

                     <button/>

                  </ui>

                  <font typeface="Arial"/>

                  <caption>

                     <value>

                        <text>-</text>

                     </value>

                     <para hAlign="center" vAlign="middle"/>

                  </caption>

                  <border hand="right">

                     <?templateDesigner StyleID apbx2?>

                     <edge stroke="raised"/>

                     <fill>

                        <color value="212,208,200"/>

                     </fill>

                     <corner/>

                  </border>

                  <bind match="none"/>

                  <event name="event__click" activity="click">

                     <script contentType="application/x-javascript">//+ GENERATED - DO NOT EDIT (ID:865726F0-122B-47D5-AB7F-0C724ABFA5A0 CRC:1110511936)

//+ Type: Action

//+ Result1: RemoveInstance("$Node2","lastindex","")

//+ Node2: form1[0].pagesubform[0].tablesubform[0].Table[0].TableRow[0]

//+ Node1: form1[0].pagesubform[0].tablesubform[0].buttonsubform[0].RemoveSubformButton1[0]

//+ Condition1: Button("$Node1","click")

//+ ActionName: RemoveSubformButton1.click

this.resolveNode('Table._TableRow').removeInstance(this.resolveNode('Table._TableRow').count - 1);

if (xfa.host.version &lt; 8) {

          xfa.form.recalculate(1);

}

//-

/*

   This button will Remove the current instance of the repeating subform or table row.

   bCalc: Flag - true if the removed instance might be referenced by other calculations, otherwise false.

   message: The error message displayed.

*/

var bCalc = true;

var message = "You have reached the minimum number of items allowed.";

// DO NOT MODIFY THE CODE BEYOND THIS POINT - 9.0.0.2.20101008.1.734229.723806 - Subform_Instance_Controls_IRM.xfo.p4

var oWrapper = this.parent.parent;          // The outer subform built in to the object, enclosing the button group.

var oTargetSubform = oWrapper.parent;          // The subform or table row the controls are intended to manipulate.

var oManager = oTargetSubform.instanceManager;          // Get the instance manager.

var nMinCount = oManager.occur.min;                              // Get the minimum number of subform occurrences allowed.

var nSubCount = oManager.count;                                        // Get the current number of instances.

// Proceed if the minimum number of subform occurrences has not been reached.

if (nSubCount &gt; nMinCount) {

 

          // Invoke the Instance Manager.

          oManager.removeInstance(oTargetSubform.index);

          // Fire the form calculations.

          if (bCalc == true) {

 

                    // Execute all the form calculations.

                    xfa.form.recalculate(1);

          }

} else {

          xfa.host.messageBox(message,"Remove Item", 3);

}

// END OF DO NOT MODIFY

</script>

Avatar

Correct answer by
Level 10

Hmm ok, the Action Builder script is very overloaded, not sure what causes the error.

My suggestion:

1. Remove all actions you created with the action builder

2. For the Add button use this JavaScript in the click event

3.For the Remove button this JavaScript (will remove always the last instance of the row)

Avatar

Level 5

The problem is that the hierarchy of subforms is incorrect. When you add the object library object Subform Instance Controls: Insert Remove Move, it automatically puts in two nested subform containers. It looks like one level of those containers has been removed and script is now failing since it cant find the correct path to the table via code.

All you need to do is right-click on buttonsubform and select Wrap in Subform and it should fix your code issue.

Avatar

Former Community Member

Tried your solution, dohanlon. It worked and it didn't work. I no longer get the error message, but it now adds an instance of the entire table, rather than the one row I want repeated.

radzmar, I'll try implementing your solution on Monday and let you know how it worked -- busy day today!

Avatar

Level 5

Yes indeed you will get repeating table if the buttons are on the table level in the hierarchy. The library object you are using needs to be in the correct place in the table. It is expecting the buttons to be on the table row itself for them to work correctly since it is an insert/delete/move action. If the buttons need to be on a table level then normal buttons with the code radzmar is suggesting would be best and not use the object library one.

Avatar

Former Community Member

Okay, I did end up having a little extra time today to try your solution, radzmar, and it worked! Thanks so much for your help. And thanks, dohanlon, for the clarification in how the items from the object library work, that's very helpful. Hopefully I can get my employer to spring for a few Javascript courses for me, but until then, I'm very glad these forums exist. Thanks!