These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

delete last instance

noos
Registered: Aug 28 2009
Posts: 20

Hello, according to the number you enter in the number field Reyers instances.

If for example I created 5 instances and insert number 4 in the field is eliminated but an objection is not the last that I have created what can I do to remove instances from the bottom ?????

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You're post does not make sense because you haven't provided a context. However , if you want to delete the last instance of a repeated subform you'd use code something like this:

For a subform named "MySub"

_MySub.removeInstance(_MySub.count - 1);

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

noos
Registered: Aug 28 2009
Posts: 20
thank's works great job :)
libraboy
Registered: Dec 14 2007
Posts: 94
Hi,

For me its not working :(

form1.Addform.Page3.AddLanguage.Language.instanceManager.removeInstance(AddLanguage.Language.count - 1);
form1.Addform.Page3.AddLanguage.Language.execInitialize();

Please check it for me... I am a newbie with the application

thanks
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Is "AddLanguage.Language.count - 1" does not reference the instance manager, which is where the "count"property is found. And why is the initialize event being run?

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gc123
Registered: Feb 11 2010
Posts: 7
Hi, I seem to be having problems deleting a specific instance from the instance manager but only when the subform, table or row has a image field embedded.

The code I have been using, does work for a normal subform/table or row but when I have an image field present the delete function appears to delete the last instance which has an image present. This has been baffling me for a while now and I'm a little stuck as how to solve this problem.

Your code does work, but it only seems to allow the user to delete the last instance. I need to be able to delete specific instances.

To give you a little more background, the form is a prototype request form and allows engineers to attached images and data of a part on to a form so that these parts can be made in our workshop. The form needs to be able to add parts (attach images and info) and also delete specific parts if no longer needed.

The following code only works if there is a delete button in each instance.

The delete code I was originally using to delete specific instances is:

var nNodes = form1.Subform2.Subform1.Table11.resolveNodes("Row1[*]").length;
if(nNodes > 1)
Row1.instanceManager.removeInstance(this.parent.index);

Where form1.Subform2.Subform1.Table11 is the parent directory
and Row1 is what I am deleting from the instance.



I have also tried your code:
For a subform named "MySub"

_MySub.removeInstance(_MySub.count - 1);

but this only seems to delete the last instance.

happy to send you the form if this helps...

Many thanks!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
For checking the number of instances you could use this code

if(_Row1.count > _Row1.min)
_Row1.removeInstance(this.parent.index);

There's no need to resolve the list of subform nodes, or hard code the minimum number of instances. This code is much more general.
However, it only works to remove a specific instance if it is executed from an element immediately inside "Row1". "Row1" must be the parent. The paths used here, "_Row1" and "this.parent" are relative. If the node is somewhere else the paths may not make any sense. So the first thing you need to do is make sure that the paths from the element containting the code to the subform you want to delete are correct.

Needless to say, the best way to make sure you're getting the correct subform to delete is to place a delete button inside the subform.

But if that button is two levels deep, then the "parent" path used in the code will be different.
For example:

if(_Row1.count > _Row1.min)
_Row1.removeInstance(this.parent.parent.index);


Have you watched the video on scripting in LiveCycle?
https://admin.adobe.acrobat.com/_a200985228/p87746471/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gc123
Registered: Feb 11 2010
Posts: 7
Hi Thom,

Many thanks for the help. Using the parent.parent function to go back a level deeper seems to have solved all my problems!

Also, the tutorial link you posted is excellent and has really helped me to get to grips with the basics.
I have completely redesigned the my whole form today; labeling each row, object and subform correctly makes things so much easier and it works perfectly as intended!

A huge huge thanks!

The only thing left which I can't seem to do is link two text fields or drop down boxes entered by the user. I realize the global function seems to do this, however it does not appear to distinguish between different instances, it thinks every instance will have the same data.

I.e. I have two lists, one is a 'list of parts' and the other a list of 'part details' (my form is an engineering data submission form).
I want to be able to add an instance to the 'list of parts' whilst also automatically adding an instance to the 'part details list'. The 'list of parts' is simply a simplified list so people in the workshop can have a quick overview of what to make. My problem is that I want to auto-fill the correct instance of the 'part details list' with the data which is repeated and already entered in the 'parts list'. I don't want the user to have to input this twice.

Getting back to the delete instance issue.. I then want to be able to delete the specific instance (which is what I can now do).

I hope this makes sense, sorry if its going a little of tangent to the forum description.

Once again many thanks for all your help!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
this two part article will help with the lists:
http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

gc123
Registered: Feb 11 2010
Posts: 7
Hi Thom,

Great article! Thanks for the link...

Is there a part 2 by any chance? I see you mention it in the article but unless I'm going mad I can't see a link.

Thanks for all the help.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You know, there was a time when there was a link to part 2 at the bottom of the page. Don't know what happened there. But here it is:
http://www.acrobatusers.com/tutorials/2007/10/list_and_combo_in_lc

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script