1. Tasks
  2. Save Data

Tasks

Save Data

Saves a new field name into the Stub's data

Basic usage

Task to save the static value of blue into stub.data.favorite_color

loading...

Parameters

fieldname
required
string

This is the fieldname to which the data will be written to in stub.data


savevalue
required
string

Data value which we want to save : blue


jsonata
optional
string

A JSONata expression can be used to determine the savevalue for advanced cases.


datatype
optional
string

Will attempt to convert the savevalue to the specified datatype.
Supported types are: text, number, integer, boolean, date, time, datetime and gps.

Result

loading...

Properties

fieldname

Name of the field created : favorite_color


savevalue

Data value saveds : blue

Examples

These are some more complex examples

Save Data with Substitution

Savedata using Substitution to derive savevalue

loading...
Result
  • Below object stored in stubpost.tasks.savedata_favorite_color and favorite_color added to stub.data
loading...

Save Data with datatype boolean

Savedata using datatype to convert the savevalue to a boolean, using JS Boolean Constructor

loading...
Result
  • Value "fieldname": "indemnity_confirmed" stored in stubpost.data.indemnity_confirmed and indemnity_confirmed added to stub.data
loading...

Save Data with JSONata

Savedata using JSONata to derive savevalue.

If the field does not exist, a default value of favorite color does not exist is returned, alternatively the value in ~~stub.data.current_favorite_color is returned.

loading...
Result
  • stub.data.current_favorite color is false
loading...

JSONata to Clean Number to E164

Savedata using JSONata to clean a phone number to E164 International Format.

TIP

You can now use the Handlebars format_phone_number Helper to perform this function.

You can also use the JSONata Hashtag Helper to perform this function.

NOTE

Required Data in stub.data
These data points can easily be modified to point to the data points in your specific schema.

loading...

default_country_code: The country Code to correct the number with. Defaults to '1' - USA if not found or given.
cellphone_number: The phone number that needs to be cleaned and corrected

The savedata would look like this:

loading...

Try it in the JSONata Exerciser

stub.data.default_country_code

optional
string

ONLY used if the cellphone number starts with a '0'

REPLACE the stub.data.default_country_code, in line 2, with the static country code as string eg. '1' or with the path to the stub data country code data point.
If the 'default_country_code' does not exist or is not given, it will default to '1' - USA country code.


stub.data.cellphone_number

optional
string

REPLACE the stub.data.cellphone_number, in line 3, with the path to the stub data cellphone_number data point.


Result
loading...