Duplicate/copy form

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

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

Cheers,
Maria

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

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.

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

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.

Hope this helps.

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