· Jul 3, 2021

Object of %SerialObject class to List


Is it possible to convert the object of type %SerialObject to $List form? I'm using embedded class in unique index and I want to use autogenerated method Open to  access the object - parameter should be in $List form...





Product version: IRIS 2020.1
Discussion (9)1
Log in or sign up to continue

Tnx for you answer, but I'm not sure I understand it. I don't have problem with index but with Open method:

        Set attributes=##class(Packing.Needs.Attributes).%New() //%SerializeObject
        Set attributes.Source="SYS"
        Set need=##class(Packing.Needs.State).StateIdOpen(json."Department",technicalProduct.%Id(),$ZDate(+$Horolog,3)_" 00:00:00",json."DeliveryBy",attributes,4) //attributes parameter should be in $List format


It works although in the documentation stays:

method %SerializeObject(ByRef serial As %Binary, partial As %Integer = 0) as %Status [ Language = objectscript ]

This method retrieves all of the serial values for referenced objects and places them into the instance variables, Validates, Normalizes, and serializes the object (with a save of the persistent image if persistent).
This method is not meant to be called directly. It is called by %Save and by %GetSwizzleObject.




Zdravo Matjaž!
you are right in principle. Though there are hundreds of similar cases since DECADES!
ok, the cleaner solution brings us back to my previous proposal.
add a calculated property to your serial class ##class(Packing.Needs.Attributes) like this

Property List As %List [ CalculatedSqlComputed,
= { set {*}= $LB({attr1},{attr2},{attr3},{attr4} ) }, SqlComputed ];

attr1,attr2,attr3,attr4 have to be the SQLnames of these properties !!!

WARNING#1: you have to maintain this list manually at every change of the attributes!

WARNING#2:: this calculation happens at every access to the object. 
The additional parameter     SqlComputeOnChange = (attr1,attr2,attr3,attr4
may reduce this. though I've never tried in practice