ToolJet/docs/docs/tutorial/transformations.md
2021-04-29 11:21:06 +05:30

1.2 KiB

sidebar_position
4

Tranformations

Transformations can be enabled on queries to transform the query results. Let's write a simple transformation to compute first_name and last_name for all the customers that we fetch in the previous step.

// write your code here
// return value will be set as data and the original data will be available as rawData
return data.map(row => { 
  return { 
    ...row,
    first_name: row.name.split(' ')[0],
    last_name: row.name.split(' ')[1]
	}
});

The query will now look like this:

ToolJet - Query result transformations

Save the query and click on the 'Run' button to run the query. We can now use the state inspector on the left sidebar to view the query result.

ToolJet - Query result transformations

We can see that first_name and last_name is added to all the rows in the data object of the query. If we need the original query data, it will be available in the rawData object of the query.

ToolJet - Query result transformations