Customizations
3 minutes to readCustom JavaScript lets you extend what a Flex app can do beyond its built-in settings. You add a script to a DataPart, and the script reacts to what happens in the app as people use it, such as a report loading its data or a form about to be submitted. You can write the script yourself, or describe what you want and let Caspi write it.
What you can do with custom JavaScript
A script is standard JavaScript that runs in the browser, so you aren’t limited to a fixed set of options. The events tell your code when to run, and what it does is up to you. Some common examples:
- Format data conditionally: highlight report rows or cells based on their values.
- Read values on the page: use the values shown in fields, rows, and charts in your own logic.
- Change form data before it is saved: clean up or fill in values when a user submits a form.
- Apply your own validation: stop a submission that fails your rules, including rules checked by another service.
- Customize the page: change the menu or page title when an AppPage opens.
How it works
Each DataPart has its own script, which you open in Designer from the DataPart’s Customization settings. A script uses the CaspioFlex helper to listen for events, and runs your code when they happen:
- AppPage events fire when an AppPage opens.
- DataPart events fire when a DataPart’s data is shown, including after every search, filter, or page change, and when the DataPart is refreshed.
- Form events fire right before a form is submitted, when you can change or cancel the submission, and after the submission attempt finishes.
Scripts refer to DataParts and AppPages through parameters such as [@datapartid:AppPageName.DataPartName], inserted from the editor. Caspio replaces each parameter with the real ID when the DataPart renders, so scripts keep working after you rename objects or move the app to another account.
Each script runs on its own. An error in one script doesn’t break its DataPart, other DataParts, or the page.
Generate scripts with Caspi
You don’t need to write JavaScript yourself. In the Custom JavaScript editor, select Ask Caspi, describe the behavior you want, and Caspi writes the script and adds it once you approve it. You can then review and edit the script like any other.
Caspi uses AI to generate scripts, and the results can contain errors. Verify that a generated script is accurate and appropriate, and test it before you deploy your app.
Frequently asked questions
- Do I need to know JavaScript?
No. Caspi can write the script from a description. Knowing JavaScript helps you review and adjust what Caspi writes. - Can I use one agent in more than one app?
No. Each DataPart has its own Custom JavaScript editor.
Read the articles below to learn more about customizations: