modify

Task purpose

The modify task creates a new variable from a modified copy of an existing variable. Its primary purpose is to modify an object key’s boolean, number, or string value. modify can create a new variable from both job variables and the outgoing variables of tasks. It works with boolean, number, string, and object data types. It does not work with array data types and will not modify elements of an array within an object.

Properties

IncomingDescription
object_to_update (required)The variable to modify. You can modify job variables, a static value (useful for testing), or an earlier task’s outgoing variable.
query (optional)If not using a query, set its reference task to static and delete the contents of its reference variable. When modifying values of boolean, number, or string type, the query is not used. If modifying an object and you only need to modify a specific field, specify a query for that field.
new_value (required)The new value, which can come from a job variable, a static value, or an earlier task’s outgoing variable. The new value replaces the value passed in object_to_update. If object_to_update is an object and a query is specified, the new value replaces only the matching field.
OutgoingDescription
updated_objectThe modified value is assigned to the immutable variable updated_object and returned to the job. Optionally check the Job Variables checkbox to create a job variable from updated_object — the immutable variable remains and a new mutable job variable is created. When creating a job variable, provide a new name to avoid naming conflicts and improve clarity.

Examples

Change a boolean value

Change the boolean value of a job variable or a previous task’s outgoing variable from false to true:

1object_to_update = <name of var>
2query = ""
3new_value = true

The value of updated_object (outgoing variable) will be true.

Change a string value

Change the string value of a job variable or a previous task’s outgoing variable from "before" to "after":

1object_to_update = <name of var>
2query = ""
3new_value = "after"

The value of updated_object (outgoing variable) will be "after".

Change a field value in an object

Change the boolean value of the "sync-status" field in an object from true to false:

1object_to_update = {
2 "name": "cr1.atl",
3 "sync-status": true
4}
5query = "sync-status"
6new_value = false

The value of updated_object (outgoing variable):

1{
2 "name": "cr1.atl",
3 "sync-status": false
4}

Change a nested string field in an object

Change the string value of the "description" field in an object:

1object_to_update = {
2 "name": "BMW-1",
3 "description": "Northeast region",
4 "endpoints": [
5 { "name": "NYC", "device": "er1.nyc" },
6 { "name": "BOS", "device": "er1.bos" }
7 ]
8}
9query = "description"
10new_value = "New England Region"

The value of updated_object (outgoing variable):

1{
2 "name": "BMW-1",
3 "description": "New England Region",
4 "endpoints": [
5 { "name": "NYC", "device": "er1.nyc" },
6 { "name": "BOS", "device": "er1.bos" }
7 ]
8}