Execute JavaScript with the Code block
Learn how to use JavaScript code in a workflow.
JavaScript is the primary method for manipulating and transforming data in Retool. Use Code blocks to write custom JavaScript code that can transform data and perform complex logic. You can also use popular JavaScript libraries to further extend the functionality of workflows.
Add a JavaScript Code block
To use JavaScript in a workflow, add a Code block to the canvas and select JavaScript.
Write and execute JavaScript code
You can build complex logic or manipulate data using JavaScript methods like map(). For example, you could transform an array of customer records using map():
const data = query1.data;
return data.map((customer) => ({
fullName: customer.name,
emailAddress: customer.email,
}));
In general, Retool recommends you visually construct conditional statements with Branch blocks or filter query results using Filter blocks.
JavaScript Code blocks can also call functions