Work With JavaScript

Define your own JavaScript functions to extend an application’s functionality for your business needs. For example, you can add a custom JavaScript function to validate whether required fields in a form have values, or to calculate the result of an add or multiply operation.

JavaScript functions are defined within the scope of a module, which can be at the application, flow, or page level. An AppModule contains one or more flows, each with its own FlowModule, and each flow can have one or more pages, each with its own PageModule. Within a page, there can be several UI events, each of which is typically associated with an action chain.

If your function will only be called in a page (say, to load some data when the page loads), you can define it within the PageModule. If you want multiple pages to call a function (say, to load libraries for customizing navigation elements or custom web components), you'll need to define the function within the FlowModule or the AppModule. If you’re working with a fragment or layout, you’d use FragmentModule or LayoutModule. Functions defined here are available only within the scope of the layout or fragment.

You can also import and reference third-party JavaScript libraries whose functions, objects, and variables you want to use in your custom code. VB Studio also supports RequireJS, a JavaScript file and module loader that simplifies the task of managing library references.