Chronicle
(Todd Manchester)
September 25, 2019, 8:59pm
1
Hello,
I have an RO struct:
// Struct: ChronicleKeyValueStrings
__namespace.ChronicleKeyValueStrings = function ChronicleKeyValueStrings() {
this.Key = {dataType : "AnsiString", value : null};
this.Value = {dataType : "AnsiString", value : null};
};
__namespace.ChronicleKeyValueStrings.prototype = new RemObjects.SDK.ROStructType();
__namespace.ChronicleKeyValueStrings.prototype.constructor = __namespace.ChronicleKeyValueStrings;
RemObjects.SDK.RTTI["ChronicleKeyValueStrings"] = __namespace.ChronicleKeyValueStrings;
and I have an array of these items:
// Array: ChronicleKeyValueStringsArray
__namespace.ChronicleKeyValueStringsArray = function ChronicleKeyValueStringsArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "ChronicleKeyValueStrings";
};
__namespace.ChronicleKeyValueStringsArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.ChronicleKeyValueStringsArray.prototype.constructor = __namespace.ChronicleKeyValueStringsArray;
RemObjects.SDK.RTTI["ChronicleKeyValueStringsArray"] = __namespace.ChronicleKeyValueStringsArray;
I need to know how to represent my data so that it is a valid return object. Here is what I have but it does not appear to be working:
var cvs = new ChronicleKeyValueStrings();
cvs.Key = "Version";
cvs.Value = "3.0";
var cvsl = new ChronicleKeyValueStringsArray();
cvsl.writeTo(cvs);
Not sure what I am missing here either?
Thanks again!
Todd
antonk
(antonk)
September 26, 2019, 2:06pm
2
This one
var cvsl = new ChronicleKeyValueStringsArray();
cvsl.writeTo(cvs);
should be
var cvsl = new ChronicleKeyValueStringsArray();
cvsl.items.push(cvs);
items
here is an JavaScript array so it supports all JS array methods like push
, map
etc
Chronicle
(Todd Manchester)
September 26, 2019, 8:43pm
3
So that makes sense, however console.log(typeof cvsl); displays object and produces this error:
BinMessage.write: Unknown type of Key - undefined
When I test the values of cvs.Key and cvs.Value they come back correct.
cvs = new ChronicleKeyValueStrings();
cvs.Key = "Version";
cvs.Value = "3.0";
cvsl = new ChronicleKeyValueStringsArray();
console.log("cvs type: " + typeof cvs);
console.log("cvs.Key: " + cvs.Key);
console.log("cvs.Value: " + cvs.Value);
cvsl.items.push(cvs);
console.log("cvsl type: " + typeof cvsl);
console.log("cvsl: " + cvsl.items[0].Key);
Results :
cvs type: object
cvs.Key: Version
cvs.Value: 3.0
cvsl type: object
cvsl: Version
The error appears when I pass cvsl even though it is clearly assigned. This is what the service is expecting:
msg.write(“ClientData”, “ChronicleKeyValueStringsArray”, ClientData);
and when I do this:
console.log("cvsl: " + cvsl.items[0].Key);
I get this:
Results :
cvsl: Version
if I want to pass into a function ChronicleKeyValueStringsArray I would just use cvsl correct?
Thanks again,
Todd
antonk
(antonk)
September 27, 2019, 11:22am
4
Hello
cvs.Key
is a complex object containing info about data type and value of that type. It should be assigned as
cvs.Key.value = "Version";
Same goes for other fields of complex structure.
When in doubt you can do something like
var cvs = new ChronicleKeyValueStrings();
console.log(JSON.stringify(cvs));
cvs.Key = "Version";
console.log(JSON.stringify(cvs));
So you’ll the object internal structure (f.e. for the code above you would notice that the Key initially had some internal structure removed by assignment)
Chronicle
(Todd Manchester)
September 30, 2019, 12:22pm
5
Anton,
I want to thank you for your time. I know I need to know JavaScript better and that I am working on. But you got me through a proof of concept and I appreciate that!
Todd