AEM Forms 6.5 introduced the ability to define JavaScript functions that can be used in defining complex business rules using the rule editor.
AEM Forms provides a number of such custom functions out of the box, but you will have the need to define your own custom functions and use them across multiple forms.
To define your first custom function, please follow the following steps:
/**
* Get List of County names
* @name getCountyNamesList Get list of county names
* @return {OPTIONS} drop down options
*/
function getCountyNamesList()
{
var countyNames= [];
countyNames[0] = "Santa Clara";
countyNames[1] = "Alameda";
countyNames[2] = "Buxor";
countyNames[3] = "Contra Costa";
countyNames[4] = "Merced";
return countyNames;
}
/**
* Covert UTC to Local Time
* @name convertUTC Convert UTC Time to Local Time
* @param {string} strUTCString in Stringformat
* @return {string}
*/
function convertUTC(strUTCString)
{
var dt = new Date(strUTCString);
console.log(dt.toLocaleString());
return dt.toLocaleString();
}
Please refer to jsdoc for more details on annotating javascript functions.
The above code has two functions:
getCountyNamesList - returns an array of string
convertUTC - Converts UTC time stamp to local time zone
Open the js.txt and paste the following code and save your changes.
#base=js
functions.js
The line #base=js specifies in which directory the JavaScript files are located.
The lines below indicate the location of JavaScript file relative to the base location.
If you are having trouble in creating the custom functions, feel free to download and install this package in your AEM instance.
The following video walks you through the steps involved in using custom function in the rule editor of an adaptive form