Skip to main content

set_field_conditional

The set_field_conditional processor sets the value for a field in any DataEntity or DataWindow. If the field already exists on a record the default behavior to is not overwrite it, but there is an option to overwrite the field value even if it exists.

Usage

Example Job

{
"name" : "testing",
"workers" : 1,
"slicers" : 1,
"lifecycle" : "once",
"assets" : [
"standard"
],
"operations" : [
{
"_op": "test-reader"
},
{
"_op": "set_field_conditional",
"conditional_field": "type",
"conditional_values": ["data1", "data2"],
"set_field": "test_prop",
"value": true
}
]
}

Example of the data and the expected results

const data = [
DataEntity.make({
id: 1,
test_prop: 'value'
}),
DataEntity.make({
id: 2,
type: 'data2'
}),
DataEntity.make({
id: 3,
type: 'data3'
}),
]

const results = await processor.run(data);

results === [
{ id: 1, type: 'data1', test_prop: true },
{ id: 2, type: 'data2', test_prop: true },
{ id: 3, type: 'data3' }
]

Parameters

ConfigurationDescriptionTypeNotes
_opName of operation, it must reflect the exact name of the fileStringrequired
conditional_fieldField name to run checks onStringrequired
conditional_valuesValues to check for given FieldAny[]required
set_fieldName of the field to setStringrequired
valueValue to set field toAnyrequired