Custom functions are one way to create reusable functions in your form. They are registered in a server-side script, and are set with a scope that allows them to be called only in other server-side scripts, or be available both server and client-side.
Arguments
Argument | Type | Description |
---|---|---|
name | String, required | Name of the function, must be unique |
func | Function | The function to execute |
scope | String, required | Where the function can be invoked. One of:helper.VARIABLE_SERVERONLY |
Example
This function has been created in a server-side page initialisation handler:
function(helper, pageName, pageInstance, mode) {
var options;
helper.createCustomFn(
'exampleFunction',
() => {
if (helper.getFieldValue('TEXTINPUT') != '') {
options = helper.getVariable('DROPDOWN_OPTIONDATA');
options.push([helper.getFieldValue('TEXTINPUT'), helper.getFieldValue('TEXTINPUT')]);
helper.setVariable('DROPDOWN_OPTIONDATA', options);
}
return options;
},
helper.VARIABLE_SERVERCLIENT
);
}
It checks for the value of a text field, and if found, adds the value to the options in a drop-down list.
The function can be invoked using .invokeCustomFn.