Skip to main content

Creating Functions

Lets take a look at the Functions application, which you can use to review functions and their parameters, even perform interactive tests with sample data.

Open the Rule Functions app under Tools, or use the search tool to find it

Rule Functions List

The list of standard functions, along with their description and category is displayed. Next, lets take a look at the function edit/builder form

Double click (or tap on mobile) to open any function

Rule Functions Edit

Here you can see the details behind the ADD function. The following table summarizes the various sections of this form.

SectionDescription
Name, DescriptionFunctions usage name and additional description
CategoryThe functional group
Function return typeNormally this specifies the data type returned by the function, but in some cases it could be undetermined (so is technically optional)
CodeThis is the actual execution of the function. More on this in the next section Function Code
Example UsageThese are pseudo code examples showing the general use; the Rules Editor will guide you through the specific syntax and usage
ArgumentsThe list of arguments or parameters which you will feed into the function. Some arguments are optional, while others will have a list of choices.
Test FunctionAn interactive testing tool to try the function

Arguments

Arguments are generally "typed", meaning that by declaring a datatype on the argument, the system can help manage the types of data you attempt to stuff into a function, or that what comes out fits nicely into the next function. For example, entering a constant value of 40 could be construed as the integer 40 int(40) or a string str("40"). To you and I these are indistinguishable in the app, so the datatype is used by the rules parsing engine to help convert data between formats and also prevent incorrect parameter use.

Argument Editing

While the order of the arguments in this list is not significant, it is best to keep them in the same order as they are presented in the Code declaration above. The Rules Editor tool will present them to you in the natural order here, so it will be more logical to have the arguments flow in the same order as they are consumed.

Code

After completing the arguments, you're ready to add the actual script to perform the function.

x + y

That's pretty trivial, but a more practical function might be one such as STR_TO_DATE() who's Code fragment is:

datetime.strptime(value, mask).date()

The above uses the datetime class to convert a string to datetime using mask, then producing just the date component.

note

The next section, Function Code, covers the Code topic in more details.

Testing

Lastly, you can use the Test Function button to plug some sample data into the function and try it out. Here is the Test Function dialog giving the ADD function a quiz:

Argument Testing

note

Many of the functions are fully testable (String, Logical, Date, Math) though some will fake a response as there isn't necessary live data to access while in the Functions app (e.g. anything DB, Calculated or Analytics related)