All Collections
Versions 3.0 and 2.0
Code Examples
Portal 2.0 Data Hooks
Split a field into two fields by a specific values
Split a field into two fields by a specific values
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

You can create a custom Data Hook® to split 2 fields by a specific value.

Let's consider an example - a person's first name and last name are both inside the same row under the firstName field. We can use the code snippet below to evaluate if there is a space (" ") between values in that row. If there is, then the code snippet below will automatically separate those 2 values into firstName and lastName fields by a specific value of a space (" ").

if (
row['firstName'] && !row['lastName']
) {
if (
row['firstName'].includes(" ")) {
const components = row['firstName'].split(" ");
row['firstName'] = components.shift();
row['lastName'] = components.join(" ");
return { row, info: [] }

This code example is for data hooks in Portal 2.0. For an example of how to do this in Portal 3.0 or Workspaces, see our "Split Column" example in the Data Hooks tab of your template.

Did this answer your question?