Creating Custom Functions
Last updated
Was this helpful?
Last updated
Was this helpful?
This guide walks through the process of creating a new – specifically, one that takes a as input, cubes it, and returns the absolute value of the cubed result.
In the Connections Builder, add a new function by clicking on the '+' icon next to User Defined Functions in the Tree and selecting User Function Definition from the menu that appears.
Under the Usage section in the Inspector, define the Namespace value as "ABS_CUBED" and leave the Binding value as "USER_FUNCTION".
Rename the function in the Tree so that it corresponds to the how the function will be called upon within the application. User Defined Functions are designated by Namespace#Binding, so this function will be renamed "ABS_CUBED#USER_FUNCTION":
Select Number from the dropdown menu on the left and label this Number variable "n":
Inserted in the Function Body, this will appear as follows:
Inserted in the Text field under Control Properties, this will appear as follows:
Once the Airscript has been finalized, check to see if the output appears as expected in the Stage. The absolute value of the cube of -3 is 27, and this is what appears in the Label, indicating that the User Defined Function works as expected:
Under the Behavior section in the Inspector, define the expected input. ABS_CUBED#USER_FUNCTION will require only a single input: a . Click on the '+' icon under Inputs:
Directly under the Outputfield in the Behavior section in the Inspector, define the expected output. ABS_CUBED#USER_FUNCTION will output , so select "Number" from the dropdown menu under Output:
In the Function Body that appears in the Stage, use to define the output of ABS_CUBED#USER_FUNCTION in terms of the given input. The following code utilizes the Airscript function as well as the multiplication operator in order to return the absolute value of the cube of the number n:
We have now created a function, ABS_CUBED#USER_FUNCTION, that takes a as input, cubes it, and returns the absolute value of the cubed result. Upon saving, this custom function will be accessible in other parts of the , to be called on like any other function.
Toggle over to the and insert a into a :
In the Inspector, access Control Properties -> Text and define a label with Airscript that utilizes ABS_CUBED#USER_FUNCTION. Hardcode the input with the expected output in mind. In this case, give ABS_CUBED#USER_FUNCTION the -3 (the absolute value of the cube of which is 27).
expect to be given to display on the Web Page. When testing a User Defined Function that returns something other than Text, this will need to be accounted for. Recall that ABS_CUBED#USER_FUNCTION returns a ; to covert this Number into Text, use it as input for the function: