# Duplicate/copy form

**URL:** <https://forum.servoy.com/t/duplicate-copy-form/10671>\
**Category:** Classic Servoy\
**Created:** [May 18, 2009, 12:09am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671 "2009-05-18T00:09:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [May 18, 2009, 12:09am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/1 "2009-05-18T00:09:11Z")

</div>

Hi All,

Did anyone try to duplicate an existing form programmatically?  
At runtime I want to create a form which is the same as an existing one except the name and location.  
But if I use solutionModel.newForm() then I will have to assign a lot of form properties and also create the fields which is quite a few lines of code.  
On the other hand, If I do \_newForm = solutionModel.newForm(…) and then \_newForm = \_oldForm, obviously it does not work, because the \_newForm is just a reference to the old form.  
Please, help.

Thanks,  
Maria

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [May 18, 2009, 12:23am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/2 "2009-05-18T00:23:38Z")

</div>

Sorry for the silly question.  
The ‘extendsForm’ property of the new form solves the problem.

Cheers,  
Maria

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [May 18, 2009, 3:27am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/3 "2009-05-18T03:27:20Z")

</div>

There is another problem with the new form.  
I cannot seem to be able to access the new form’s elements.

\_newForm.getFields() gets an empty array.

After showing the new form forms[\_newForm.name].elements shows all elements as they are expected to be.

However I need to assign a valuelist to a field on the new form (other than the one on the base form) and the only way to do that that I know is in solution model (which cannot see the fields). Can anyone help?

Thanks,  
Maria

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [May 18, 2009, 7:47am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/4 "2009-05-18T07:47:37Z")

</div>

Hi Maria,

When you extend a form into a new form then this new form doesn’t really hold the original form elements.  
They are ‘owned’ by the original form.

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [May 18, 2009, 11:49pm UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/5 "2009-05-18T23:49:15Z")

</div>

Hi ROCLASI,

The Servoy Developer Guide talks about creating a copy of a form (duplicate a form) “including all form objects/elements - and enable any aspect of the form to be edited separately from other forms”. Isn’t it the behavior that I expect? Maybe there is another way to copy a form and be able to edit the new form’s elements?

Thanks,  
Maria

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [May 19, 2009, 6:14am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/6 "2009-05-19T06:14:34Z")

</div>

Hi Maria,

When you use Form Inheritance (i.e. extend) then the parent form is not really part of the new form. The new form just inherits the elements and it’s properties from the parent form.  
You can’t change the design time properties (valuelist assignment on a field for example) on the inherited elements. You can only do that on the parent but that would change it for all forms that used this form as parent. Runtime properties should be accessible from the child form though (enable/visible/etc.).

If you want to copy a form at runtime I think the only way is to create a new form and recreating all the elements by code.  
If you want an easy copyForm function in the solution model I suggest you [file a feature request](http://www.servoy.com/s).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![maria](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@maria](https://forum.servoy.com/u/maria)\
**Post date:** [May 20, 2009, 12:07am UTC](https://forum.servoy.com/t/duplicate-copy-form/10671/7 "2009-05-20T00:07:19Z")

</div>

Thanks ROCLASI,

I found another way around. The valuelist is still the same for the new and old forms’ fields, however different values are set onFocusGained for the fields.

Cheers,  
Maria
