Add a Custom JavaScript Function
To add a custom JavaScript function, you define the function within the Module class provided in the JavaScript editor for your page, flow, or application. You can also do this for layouts and fragments.
-
In an action chain, select the function in the Call Function action.
Let’s say your UI requires you to enter some text in an input component, then click a button to call a function that passes that text, modifies it, and binds it to an output component. The input component is bound to an InputVariable and the output component is bound to an OutputVariable. You now build an action chain that's triggered when the button is clicked, where a Call Function action calls the custom function and maps its input parameter to the InputVariable, followed by an Assign Variable action that assigns the output of the function to the OutputVariable:
Description of the illustration jscallfunction.jpg
-
In a component's Properties pane, select the function in the Expression editor or Variables picker of a property.
Let's say your UI fetches data from a REST service and you want to convert some values shown in an Input Date Time component. By adding a converter function that uses the IntlDateTimeConverter API, you can select your custom function in the Variables picker to convert the value to a suitable date-time format:
Description of the illustration js_functions_variablepicker.pngTo write efficient expressions that handle situations where a referenced field might not be available or the field's value could be null, see How Do I Write Expressions If a Referenced Field Might Not Be Available Or Its Value Could Be Null?