User Tools

Site Tools


usingarrayvalueobjectstopassmuliplevalues

Using Array Value Objects to Pass Multiple Values to a Script

An ArrayValueObject contains one or more ValueObjects stored in an internal vector. Filling an ArrayValueObject with ValueObjects which contain data for a script is one way to pass multiple values to a script. In this article we will show you how to build an ArrayValueObject (AVO) of data values and pass it to a script in a named BroadcastServer (“Variable”) in a /Devices/ node or to a BroadcastServer in your MIStudio logic.

The purpose of this example is to demonstrate a way that you can trigger a script with a single ValueObject composed of multiple values. This is useful for when you need to pass multiple instance values (values valid at a specific point in time) to a script.

There are other ways to pass multiple values to a script. For example, you may be able to read a row of data values from a database table (using DatabaseRowArrayLookup which returns an AVO). You can also fill a “MAP” property and add it to a ValueObject to pass to your script. A “MAP” property is a HashMap (key,value) set of entries. Using a HashMap is covered in this article: Using a MAP property in a ValueObject

The Data and the AVO

To use ArrayValueObjects in your script you need this Java variable declared:

var ArrayValueObject = Java.type("com.ergotech.vib.valueobjects.ArrayValueObject");

For this example we will set up a combination of server values and static strings to build the collection of value objects for the ArrayValueObject.

Note: the order in which the values are added to the ArrayValueObject is important. The values will be added starting at an index of 0, then 1, then 2, etc. When you use this ArrayValueObject in your script you must respect this order when you access the values in your script.

//make an ArrayValueObject of two LongValueObjects and one StringValueObject
//declare the object classes
var LongValueObject = Java.type("com.ergotech.vib.valueobjects.LongValueObject"); //for storing integers
var StringValueObject = Java.type("com.ergotech.vib.valueobjects.StringValueObject"); //for storing Strings
 
value1 = new LongValueObject(2);
param2 = /Devices/UtilityServers_Servers/Parameter2->getIntValue(); //use a stored value 
value2 = new LongValueObject(param2);
value3 = new StringValueObject("Hello");
 
avo = new ArrayValueObject();
avo.addElement(value1);
avo.addElement(value2);
avo.addElement(value3);
 
//now the avo is ready to be passed to your script

Triggering the Script with the AVO

The script is triggered with the ArrayValueObject by using the setValueObject() on the bean containing the script.

For example:

/Devices/UtilityServers_Servers/CalculateSomething->setValueObject(avo);

or in MIStudio you would do this to pass the AVO to a BroadcastServer named “SomeScript”:

/Main/SomeScript->setValueObject(avo);

Decomposing the ArrayValueObject in the Script

The incomingValue of the script in your BCS (in MIStudio) or /Devices/ server in TransSECS will be the ArrayValueObject you passed to it.

To use the AVO, get one element at a time for your script. Using the example above, the AVO has three elements: a LongValueObject, a LongValueObject, and a StringValueObject.

if (incomingValue.getQuality()==0) { //always check for good quality
 
  vo1 = incomingValue.elementAt(0); // LongValueObject
  vo2 = incomingValue.elementAt(1); // LongValueOject
  vo3 = incomingValue.elementAt(2); // StringValueObject
 
  v1 = vo1.getIntValue(); //get the integer value from the ValueObject
  v2 = vo2.getIntValue();
  v3 = vo3.getStringValue();
 
//use v1,v2, and v3 in the rest of your script....
 
}
incomingValue;
usingarrayvalueobjectstopassmuliplevalues.txt · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki