Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to remove instances dynamically based on parameter from row objects

Avatar

Level 2

Hi , guys

I'm using Adobe LiveCycle 10.4.0  ES2.0.​ ​I get confusing about using removeInstance(). I want to delete the row items based on parameter from data structure.  And my codes seems noneffective. My codes in table layout:ready* is :

var valFs;

var numrows = xfa.resolveNodes("SRFS_PL_FINSTMNT_XSD_REP_DATA.bdyMain.tblLineItems.rowLineItem[*]").length;

for (var x=0; x < numrows; x++)

{

      valFs = xfa.resolveNode("$record.LISTFINSTMNT.item[" + x  + "].FSTYPE").value;

      if (valFs == "AA")

    {

        SRFS_PL_FINSTMNT_XSD_REP_DATA.bdyMain.tblLineItems.rowLineItem.instanceManager.removeInstance(x);

    }

}

Actually, the result really delete some items, but it seems delete row items randomly. Can you please answer how to use removeInstance() if I want to delete row items depend on another parameter in table? Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi, you should go though your table backwards, so "for (var x=numrows -1; x >= 0; x--)" as deleting rows will change the number of rows but you have already calculated numrows.

Also, you should not do this in the layout:ready event as it will cause the event to fire again, see this reference https://helpx.adobe.com/pdf/aem-forms/6-3/scripting-basics.pdf#nameddest=G6.1668520

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi, you should go though your table backwards, so "for (var x=numrows -1; x >= 0; x--)" as deleting rows will change the number of rows but you have already calculated numrows.

Also, you should not do this in the layout:ready event as it will cause the event to fire again, see this reference https://helpx.adobe.com/pdf/aem-forms/6-3/scripting-basics.pdf#nameddest=G6.1668520

Avatar

Level 2

Hi BR001,

Thanks, it really works.

BR, PiPi Li