Call Custom JavaScript Functions

You use a JavaScript editor to add custom JavaScript functions that can be called from within pages, components, action chains and fields in your extension. Any JavaScript code that you add will have a defined scope based on the editor where you write the code. If you have some JavaScript code that will only be called from within a specific Layout, you can write your code in that Layout's JavaScript editor.

Each page and Layout has a separate JavaScript file that you open in their respective JavaScript editors. For example, you open the JavaScript file for the FoDProducts Layout by clicking the Layout's JavaScript tab, or by locating the Layout's JavaScript file (layout-x.js) in the Source view in the Navigator. After adding the code, you can then call the functions from the Layout's action chains and components.



Layouts also have a JavaScript file for custom functions used in properties for the Layout's fields. You can edit this file by opening a Layout's Fields tab and then selecting the JavaScript editor in the header, or by locating the JavaScript file for the Layout's fields (data-description-x.js) in the Source View in the Navigator.



The editor provides code validation and identifies the lines that contain syntax warnings and errors in the right margin of the editor. A lightbulb in the left margin indicates a hint for correcting invalid JavaScript code.

Note:

The auto-save function will not save a JavaScript file that has invalid code.

You can use custom JavaScript functions: