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 custom JavaScript to perform calculations, validations, and other custom logic in your app. When you add the Code block, you will see a sample code appear. This sample code is only for your reference on how the Code block works and can be completely removed or replaced with your required code.
What the sample code is about:
Tip: If you’re unsure about writing the code, you can use AI tools like ChatGPT, Claude, or Gemini to generate it for you. You can copy the sample code shown in the Code block and paste it into the AI to help it understand the required structure. Then ask it to generate your required code in the same format.

The Output Fields section is where you define which values returned by your code will be available as variables for use in other blocks. These names must match the output names that are defined and returned inside your code.
Using the sample code above as an example, the code returns two outputs: sum and prod. To make these available outside the Code block, you need to manually add them here.
In the Output Field text box, type:
Then click on Add another field and type:
Once added, both sum and prod will be available as variables that you can use in other blocks such as the Calculation & logic block, for display conditions, etc. Only the values that are returned by the code can be added in the output fields.
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.
The variables for the sample example would be {code#sum} and {code#prod}.

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.
L374, 1st Floor, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India
3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA

3500 S DuPont Hwy, Dover,
Kent 19901, Delaware, USA
L374, 1st Floor, 5th Main Rd, Sector 6, HSR Layout, Bengaluru, Karnataka 560102, India

