Studio allows users to create and inject their own custom functions into their applications. This is useful when a user wants to manipulate data in certain cases or to run a small script in certain events. These are called Studio Functions.
Studio Functions work as a mediator or data processor for controls. Take for instance you have certain data coming in from an API and you want to remove all null values. In a case where there are no custom functions, the data is directly fed into the controls you are trying to insert data into. You can manipulate this data by passing this into a function.
We will take an example of the concatenation of strings.
Opening the Function Editor
To open Studio Functions editor, go to Studio console > Extensions> click Function Editor.
Creating a new studio function
To create a Studio Function, go to Studio console, click on Function Editor.
To create a new function, click on + New (add new function)
In the above form, create a unique name for your function, we are going to use Dhqsampletest as the function name.
Once you’ve created the function, your screen will look like this.
You can add your code logic inside the function. Make sure you have a try-catch inside the function to avoid issues.
In the above use case, we have passed 2 parameters into the function, namely, firstName and lastName. These two are then concatenated with a space to resemble the full name of a user.
Once done, click Publish to make the function live. You can now use the function in the Studio as shown below.