How do I save the value in obj.%Size() to a variable ?
Hi all, I am new to IS Objectscript and I would appreciate some assistance regarding this.
I am trying to find out how to count the number of elements within a dynamic abstract object and I am having some trouble using the size method.
Here is the code below:
The key value pairs are originally in JSON and I would have converted it in to an object for use.
Class JSON.Test {
ClassMethod Test()
{
set obj = {"byr:":"1937", "iyr:":"2017", "eyr:":"2020", "hgt:":"183cm", "hcl:":"#FFFFFD","ecl:":"grey", "pid:":"028048884"}
set passport1 = {"ecl:":"grey","pid:":"860033327", "eyr:":"2020","hcl:":"#FFFFFD","byr:":"1937", "iyr:":"2017", "cid:":"147", "hgt:":"183cm" }
do ..FirstPassport(passport1)
}
ClassMethod FirstPassport(passport1 As %DynamicObject, property = "")
{
write !
set iterator = passport1.%GetIterator()
write "Number of properties: "
set property = _passport1.%Size
// I would like to be able to save the above mentioned property as an value and use this as a condition to determine if the property is 8 then write the key value on to the screen.
while iterator.%GetNext(.key, .value) {
write key_value, !
}
write !
}
}
Product version: IRIS 2020.1
$ZV: IRIS for UNIX (Ubuntu Server LTS for x86-64 Containers) 2020.4 (Build 547U) Fri Apr 2 2021 16:44:21 EDT
Why so complicated?
should do the job
Sorry my mistake I need to rephrase the question. I will modify it
How do I save the value in obj.%Size() to a variable ?
Somehow I don't get you right. To save obj.%Size() in a variable, just do a simple assign
but I'm pretty shure, this was not your intended question.
I suppose, you have JSON formatted data (a string or a stream) and you want to store those data in a table. Am I right?
If yes, then follow the next steps:
1) create a class which describes your JSON objects (strings)
2) You can create some test data (interactively) in a terminal session
or get your data somehow from an input (possibly from a file), the only important thing is, your data should look like this
3) import those data
4) Now open the saved data and check the result
I hope, this is what yoy want to do...
Hi Julius, yes your answer went above and beyond my expectations and I would like to thank you personally for your response. It is very much appreciated !
If it helped you to understand how things work, then everything is OK. Have a nice day.
Please ask it as a separate question.
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue