docs/versioned_docs/version-2.9.0/data-sources/custom-js.md
You can write custom JavaScript code to interact with components and queries. To do that, you just need to create a new query and select Run JavaScript Code from the data sources dropdown.
<div style={{textAlign: 'center'}}> </div>+ on the query panel to create a query and select Run JavaScript code from the available datasourcesconst a = Math.floor(Math.random() * (10 - 1)) + 1;
return a;
:::tip
The return statement is used to end the code and the value specified to the return statement will be stored in the data property of the query.
ex: {{queries.runjs1.data}}
You cannot use console.log in Run JavaScript code
:::
Let's edit the properties of widgets:
runjs1 query that we created. This will run the JavaScript code every time the button is clicked.{{queries.runjs1.data}}. It will display the output as Random number: result from JS codeYou can also write custom JavaScript code to get the data from External APIs and manipulate the response for graphical representation. Here's the tutorial on how we used custom JavaScript code to build an app using GitHub API.
ToolJet allows you to internally utilize these libraries:
| Name | Documentation |
|---|---|
| Moment | https://momentjs.com/docs/ |
| Lodash | https://lodash.com/docs/ |
| Axios | https://axios-http.com/docs/intro |
:::info Issues with writing custom JavaScript code? Ask in our Slack Community. :::