The Code Block in Clappia allows you to write custom JavaScript code, giving you greater flexibility to handle advanced logic and calculations within your app. The output from the code can be used across various blocks, such as the ‘Calculations & Logic’ block or the ‘Text, Embedding & HTML block’, to display or use the results of your custom code.
Go to Design App > Add Field, and click on the Code Block. You can now configure the code and output fields by editing on the right panel.
Give a name to the field.
The Code section is where you write your custom JavaScript. When you add the code block, a sample function appears as follows:
In this example:
The Output Field is where you define which outputs from the code will be available as variables for use in other blocks. For example, in the above code, if you define the output field as sum, the app will recognize sum as a variable that can be used in other blocks.
You can add multiple output fields by clicking on ‘Add another field’ and entering their names one by one:
These outputs can then be pulled into other blocks, such as Calculations & Logic.
Once you’ve defined the output fields, they can be used in other blocks:
Calculations & Logic Block: Add this block to your app and pull in variables generated from the Code Block (e.g., sum, prod). Go to the right panel under ‘Formula’ and type @ followed by the name of the Code Block. A list of all available variables from the code will appear, allowing you to select and use them. You can add multiple ‘Calculations & Logic’ blocks to display individual outputs from the Code Block or combine them for more complex calculations.
In the App Home, if you’ve chosen to display the sum using the Calculations & Logic block, the sum will appear based on the values generated by the code.
Do note that the code block by itself does not appear in App Home, only the variables used in other blocks such as the Calculations & logic block to display the output will appear.
After configuring your code, test it to ensure the outputs are working as expected. In App Home, you can interact with the app and see the results from your code. If you encounter any issues, check the code for errors and ensure that your output fields are correctly defined and linked to the respective blocks.
By using the Code Block, you can introduce complex logic, calculations, and advanced functionality to your Clappia app.
140L, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India
+91 96418 61031
3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA
+1 (341) 209-1116
3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA
+1 (341) 209-1116
140L, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India
+91 96418 61031