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.

Problem with remove.instance script

Avatar

Former Community Member

Items that are scripted to be removed with this script reappear on the form after it is saved and re-opened.

Sample text (I am trying to remove a table):

_Subform_WS0941_Table.instanceManager.removeInstance(0);

Is there a master form setting that I need to setup. I looked at the Purchase Order sample provided with the software and it works just how I want it to work but cannot figure out how it is different form the form I am attempting to create.

Any guidance would be grstly appreciated.

Thanks

3 Replies

Avatar

Level 10

Hi,

A couple of things:

I would not use an underscore in the object's name, as "_" is used as shorthand for instanceManager.

What is the name of the repeating object? Is it "_Subform_WS0941_Table"?

The parameter in the removeInstance is the instance that you want to remove, based on a zero numbering system. So using "0" will always remove the first instance. This may not be what you want.

Lastly, if you go to the File > Form Properties > Defaults tab and make sure that the preserve script changes is ticked for Automatic.

Preserve script changes.png

Hope that helps,

Niall

Assure Dynamics

Avatar

Former Community Member

Nial,

Thanks for your response. See my comments and screen shots below:

Steve

Screen shots:

Beginning:

Before.gif

After

After.gif

Hi Niall,

A couple of things:

I would not use an underscore in the object's name, as "_" is used as shorthand for instanceManager.

Removed underscores & rewrote the script two different ways:

·         SubformWS0941Table.instanceManager.removeInstance(this.parent.index);

·         SubformWS0941Table.instanceManager.removeInstance(0);

What is the name of the repeating object? Is it "_Subform_WS0941_Table"?

  •     Yes, but renamed to “SubformWS0941Table” per your suggestion.

The parameter in the removeInstance is the instance that you want to remove, based on a zero numbering system. So using "0" will always remove the first instance. This may not be what you want.

  • That is precisely what I want to do. The referenced table should only show up once. If it is not needed, the user needs to have the ability to delete the table entirely from view and not have it show up again when the forms is re-opened.

Lastly, if you go to the File > Form Properties > Defaults tab and make sure that the preserve script changes is ticked for Automatic.

  • The setting was set as indicated.

Tried your suggestions with the same result.

Avatar

Level 10

Hi Steve,

Can you select the repeated object and go to the Object > Binding tab. Check that the min count and initial count boxes are NOT ticked. I suspect that one of these is ticked and therefore once the form is reopened, it is rendering an instance.

Does that help?

Niall

Assure Dynamics