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
Parameters
required string
fieldname This is the fieldname to which the data will be written to in stub.data
required string
savevalue Data value which we want to save : blue
optional string
jsonata A JSONata expression can be used to determine the savevalue for advanced cases.
optional string
datatype Will attempt to convert the savevalue
to the specified datatype.
Supported types are: text
, number
, integer
, boolean
, date
, time
, datetime
and gps
.
Result
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
Result
- Below object stored in
stubpost.tasks.savedata_favorite_color
andfavorite_color
added tostub.data
Save Data with datatype boolean
Savedata using datatype
to convert the savevalue
to a boolean, using JS Boolean Constructor
Result
- Value
"fieldname": "indemnity_confirmed"
stored instubpost.data.indemnity_confirmed
andindemnity_confirmed
added tostub.data
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.
Result
- stub.data.current_favorite color is false
JSONata to Clean Number to E164
Savedata using JSONata to clean a phone number to E164 International Format.
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.
Required Data in stub.data
These data points can easily be modified to point to the data points in your specific schema.
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:
Try it in the JSONata Exerciser
stub.data.default_country_code
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
REPLACE the stub.data.cellphone_number
, in line 3, with the path to the stub data cellphone_number data point.