If you’re a fan of macros in the code editor, then 4D v18 R5 has some good news for you … because now macros are also available in the form editor!
Let me start by telling you how useful macros can be for you. Have you ever needed to use formatting or naming rules in your application, then apply them to each new form? Or maybe you’ve had to work on existing forms created by someone else, and always need to do the exact same checks and analyses before getting started. If you’ve ever encountered one of these scenarios, then 4D v18 R5 is for you because it gives you the ability to create macros and save time on predictable, repetitive tasks.
What can a form macro do?
With a form macro, you can:
- Modify, delete, or add a property to one or more objects
- Add or delete one or more form objects with its associated method
- Select or deselect form objects in the editor
- Display a modal dialog to enter a parameter on the fly
- Calculate the ideal position of form objects and move them
- Create a CSS class from a form object to use as a template
- Check that image paths in the form are valid
- Open CSS files in your CSS editor instead to searching the files on disk
- Check that XLIFF references have their correspondence in the XLIFF files
- and so much more …
How to use a form macro?
Form macros are visible from the contextual menu. Host database macros are displayed first, followed by component macros. To execute a macro, simply click on the menu item.
How to Write a macro?
Macros are declared in a formMacros.json file at the first level of the Sources folder in your project. You can have macros in the host application or in project components. The code of the macro consists of a class: constructor and an onInvoke function. Macro classes are instantiated when the application is launched. When a developer calls the macro in a form, the onInvoke function is called.
For more details about all of the parameters, read the macro documentation.
Try it yourself
Some macro examples are available on GitHub which you can integrate into your applications as components to test them … and why not share your macros with us?