Transform data with JavaScript
Last updated
Last updated
© 2024 UI Bakery
UI Bakery allows transforming the data that comes from a database or an API by writing JavaScript code. You can do this by adding another action step inside your action and adding JavaScript code that will do what you need. Below, we'll show you how to do that based on the use case of adding a Full name property as a concatenation of the First and Last name properties.
Go to your action (for example, Load Users) and and another action step of the JavaScript Code type.
Next, write your code in the JavaScript field. In our case, we added the following code:
Click Execute action.
Your new property will be added to the result of the Load Users action as well as to the list of table columns. All components connected to this action will now also receive a new data set.
You may need to regenerate the structure of your component once again for the new property to appear.
Now, you can add another column to the table that will display the Full name of the user. You can also change the order of the columns and hide the ones that display First and Last name separately.
That's it! Now let's proceed to the next step and find out how you can change your component data.
If you want to learn more about data mapping and transforming, have a look at this article