# Properties

### Property Class

The Property class allows you to manage global and local properties used in your scripts.

**Static Properties**

* ~~`Property.global`~~ **(Deprecated)**:  A static property that holds a global PropEnvironment for managing global properties.

```typescript
var globalEnvironment = Property.global;
```

* `Property.local`: A static property that holds a local PropEnvironment for managing local properties.

```typescript
var localEnvironment = Property.local;
```

***

### PropEnvironment Class

The PropEnvironment class is used for managing properties in a specific context, providing essential methods for property management.

**Methods**

* `set(propertyId: String, value: any): void`: Sets a property in the current environment for a specified `propertyId` and assigns it the provided value.

```typescript
localEnvironment.set("myProperty", 42);
```

* `get(propertyId: String): any`: Retrieves the value of a property with the given `propertyId` from the current environment.

```typescript
var propertyValue = localEnvironment.get("myProperty");
// returns 42
```

* `inc(propertyId: String): Integer`: Increments the value of the property with the specified `propertyId` in the current environment and returns the new value as an Integer.

```typescript
var newValue = localEnvironment.inc("myProperty");
```

* `dec(propertyId: String): Integer`: Decrements the value of the property with the specified `propertyId` in the current environment and returns the new value as an Integer.

```typescript
var newValue = localEnvironment.dec("myProperty");
```

* `counter(propertyId: String): Integer`: Returns the current value of the property with the given `propertyId` without modifying it.

```typescript
var currentValue = localEnvironment.counter("myProperty");
```

### Examples

**Example:&#x20;**~~**Set Global Property**~~**&#x20;(Deprecated)**

**Description**: This script sets a global property that can be accessed across different iterations globally for the current execution.

**Use Case**: Useful for sharing data and settings across multiple nodes within your data processing.

```javascript
// The value can be any data type; here we inserted a constant string value
Property.global.set("globalProperty1", "this is a test value");

// To read the property value (can be read anywhere, in the nodes that are successors of this node)
var propertyValue = Property.global.get("globalProperty1");
```

Global Properties obtain their values at the initiation of the iteration. They are promptly evaluated and added so that any node within the workflow can access and utilize them.

**Example: Get Global Property**

**Description:** To get the value of the global property you can simply write the ID of the propriety.

<pre class="language-javascript"><code class="lang-javascript">// Getting the value of GLOBAL1 (Preferred approach)
GLOBAL1

// Getting the value of GLOBAL1 (Deprecated - not recommended)
<a data-footnote-ref href="#user-content-fn-1">Property.global.get("GLOBAL1")</a>
</code></pre>

***

### Local Properties

Local Properties are defined per node using the 'add property' button under *properties tab*. They can only be read in the current iteration.

**Example: Set Local Property**

**Description**: This script sets a local property that can be read only within the current iteration.

**Use Case**: Valuable for temporarily storing and accessing data within a specific iteration.

```javascript
// The value can be any data type; here we inserted a constant string value
Property.local.set("localProperty1", "this is a test value");

// To read the property value (can be read anywhere, in the nodes that are successors of this node)
var propertyValue = Property.local.get("localProperty1");
```

These properties enable you to transmit and retrieve data, either globally or within the current iteration, as required.

### **Example: Max Value**

The following script calculates the maximum value of an Integer column in a table and assigns it to a property named MAXVALUE. It sorts the table based on the sixth column in descending order and then retrieves the maximum value from the first row of that column. Here's the code snippet with comments:

```javascript
// Get a copy of the table reference from the previous node
var table = NodeInputReader.inputAsDataFrame(0);

// Get a new table sorted by the sixth column in descending order
table = table.sortOn(-6);

// Get the values of the 6th column from the first row (Index 0)
var maxValue = table.column(6).get(0);

// Assign the maximum value to the MAXVALUE property
Property.local.set("MAXVALUE", maxValue);
```

This code is employed to extract and store the maximum value in a local property named MAXVALUE, which can then be utilized in subsequent scripting.

[^1]: Deprecated
