new ArrayOutputReturn(output)
Creates a wrapper for the results produced by ArrayOutput.
This object allows convenient inspection of values, errors and status.
Example
Basic inspection
var { ArrayOutput } = require("sigma/arrayoutput");
var out = new ArrayOutput();
out.add(deviceA, "OK");
out.add(deviceB, null, "Timeout");
var ret = out.getReturn();
print(ret.values()); // ["OK", null]
print(ret.errors()); // [null, "Timeout"]
Parameters:
| Name | Type | Description |
|---|---|---|
output |
Array.<Object> | Internal array with |
Methods
findObj(obj) → {number}
Return index of the object in the output list.
Example
var index = ret.findObj(deviceA);
if (index >= 0) {
print("Found at index " + index);
}
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object |
Returns:
- Type
- number
get(objopt) → {Array|*|null}
Retrieve all records, or the value for a specific object.
Examples
Get all entries
var all = ret.get(); // returns array of {name, object, value, error}
Get value for one object
var valueA = ret.get(deviceA);
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
obj |
Object |
<optional> |
Returns:
- Type
- Array | * | null
lastError() → {Object|undefined}
Returns the most recent error entry.
Example
var lastErr = ret.lastError();
if (lastErr) {
print("Last error object = " + lastErr.object);
print("Error = " + lastErr.error);
}
Returns:
- Type
- Object | undefined
success() → {boolean}
True if all entries have no error.
Example
if (ret.success()) {
print("All operations succeeded.");
} else {
print("Some operations failed.");
}
Returns:
- Type
- boolean
toString() → {string}
String summary of the result set.
Example
print(ret.toString()); // "ArrayOutputReturn: N elements"
Returns:
- Type
- string