--- id: run-js title: Run JavaScript Code --- The **Run JavaScript Code** feature in ToolJet allows custom JavaScript code to be executed to enhance application interactivity. This feature is useful for performing calculations, generating values, or interacting with queries and components.
### Calling Another Query with Parameters
Parameters can also be used to trigger other queries and pass custom values. Below is an example of how to call one query from another by providing custom parameters.
1. Begin by creating a new RunJS query named _multiply_.
- In this query, add the following parameters:
- _num1_ with a default value of **10**
- _num2_ with a default value of **2**.
- Add the following JavaScript Code:
```javascript
return parameters.num1 * parameters.num2;
```
- To display the result, place a text component on the canvas and set its text to `{{queries.multiply.data}}`.
2. Now, let's create another RunJS query called _callMultiply_, where we will invoke the _multiply_ query created earlier using custom parameter values. Here's the code snippet for _callMultiply_:
```js
queries.multiply.run({ num1: 20, num2: 7 });
```
By executing this code within _callMultiply_, we trigger the _multiply_ query with specific values for its parameters.
With this setup, the _multiply_ query can be called from other queries, such as _callMultiply_, by providing custom parameter values. This allows you to reuse the _multiply_ query with different inputs and display the results accordingly.
### Generating a Unique ID
The following code generates a unique ID in the format "id" followed by a sequence of random hexadecimal characters.
```js
var id = "id" + Math.random().toString(16).slice(2);
return id;
```
For example, it could be something like "id2f4a1b".
### Generating a Timestamp-Based Unique ID
In this code, the resulting ID will have the format "timestamp + randomHex", where "timestamp" is the current time in base-32 and "randomHex" is a random hexadecimal value.
```js
return String(Date.now().toString(32) + Math.random().toString(16)).replace(
/\./g,
""
);
```
This ID will be longer than the one generated earlier, and it could look like "2g3h1d6a4h3".
:::tip Resources
- You can also write custom JavaScript code to get the data from **External APIs** and manipulate the response for graphical representation. Here's the [tutorial](https://blog.tooljet.ai/build-github-stars-history-app-in-5-minutes-using-low-code/) on how we used custom JavaScript code to build an app using GitHub API.
- [Import external libraries](/docs/how-to/import-external-libraries-using-runjs) using RunJS.
- [Intentionally Fail](/docs/how-to/intentionally-fail-js-query) a RunJS query.
- [Trigger query at specified intervals](/docs/how-to/run-query-at-specified-intervals) using RunJS.
:::