0 / 0
Setting properties

Setting properties

Nodes, flows, models, and outputs all have properties that can be accessed and, in most cases, set. Properties are typically used to modify the behavior or appearance of the object. The methods that are available for accessing and setting object properties are summarized in the following table.

Table 1. Methods for accessing and setting object properties
Method Return type Description
p.getPropertyValue(propertyName) Object Returns the value of the named property or None if no such property exists.
p.setPropertyValue(propertyName, value) Not applicable Sets the value of the named property.
p.setPropertyValues(properties) Not applicable Sets the values of the named properties. Each entry in the properties map consists of a key that represents the property name and the value that should be assigned to that property.
p.getKeyedPropertyValue( propertyName, keyName) Object Returns the value of the named property and associated key or None if no such property or key exists.
p.setKeyedPropertyValue( propertyName, keyName, value) Not applicable Sets the value of the named property and key.

For example, the following script sets the value of a Derive node for a flow:

stream = modeler.script.stream()
node = stream.findByType("derive", None)
node.setPropertyValue("name_extension", "new_derive")

Alternatively, you might want to filter a field from a Filter node. In this case, the value is also keyed on the field name. For example:

stream = modeler.script.stream()
# Locate the filter node ...
node = stream.findByType("filter", None)
# ... and filter out the "Na" field
node.setKeyedPropertyValue("include", "Na", False)
Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more