Save to state action

With the Save to State action you can save temporary values to the State. This is useful when you want to use the same value in multiple steps of your workflow.

The saved value is available as {{state.<key>}} in all actions and components.

First, create a variable to store the value you want to save, make sure to select a proper variable type.

Then, use the Value field to pass the data you want to save.

Saving a result of the previous step:

{{data}}

Additionally, you can save state values in the Code action:

state.varName = 'newValue';

// or using setValue method
state.setValue('varName', 'newValue');

read with the state.getValue method:

const value = state.getValue('varName');

reset a variable to the initial value:

state.resetValue('varName');

or reset all variables:

// reset all variables, page and app state
state.resetValues();

// reset all page variables
state.resetValues('page');

// reset all app (global) variables
state.resetValues('app');

Also, you can adjust the data before saving it.

Add additional values

const values = {{ui.form.value}};

return {
  ...values,
  created_at: new Date(),
}

The created_at column must exist in the table schema, otherwise it will not be sent.

Change the values

const values = {{ui.form.value}};
return {
  ...values,
  name: values.name.toUpperCase(),
}

Delete unwanted values

const values = {{ui.form.value}};
delete values.age;
return values;

alternatively:

const values = {{ui.form.value}};
const { created_at, ...rest } = values;
return rest;

Join array values

const values = {{ui.form.value}};
return {
  ...values,
  tags: values.tags.join(','),
}

Use default values

const values = {{ui.form.value}};
return {
  ...values,
  // if the value is not set, use the default value
  created_at: values.created_at || new Date(),
}

Last updated