Question Smythe Smythee · Nov 16, 2022

How to get values from a serialobject class

Hi,

I

want to get the values from a serial property because my code depends upon the class serial class.

For example

Serial class

Class Data.Serial Extends %SerialObject

{

Property FirstName as %String;

Property LastName as %String;

}

Persistent class

Class Data.Persistent Extends %Persistent

{

Property MPID as %Integer;

Property Name as Name.Serial;

}

Now i need save MPID and Name(Serial class property into SQL Table ) so i am trying the below class

Class Data.TestUtil Extends %RegisteredObject

{

Method Savedata(MPID,FirstName,LastName)

{

Set tSC=0

Set Obj=##Class(Data.Persistent).%New()

Set Obj.MPID=MPID

Set Obj.FirstName=FirstName
Set Obj.LastName=LastName

Set tSC=Obj.%Save()

Quit tSC

}

}

But data is not getting saved into SQL data and throwing an error, How to save serial class Property into the SQL table?

Thanks,

Smythee

Product version: Ensemble 2018.1
$ZV: Cache for Windows (x86-64) 2018.1.1 (Build 312_1_18937U) Fri Apr 26 2019 17:58:36 EDT

Comments

Julius Kavay · Nov 16, 2022

If your serial class is named Data.Serial (as in your example code) then you should use the same name for the serial property too

Class Data.Persistent Extends%Persistent
{
Property MPID as%Integer;Property Name as Data.Serial;   <--- !!!!!
}

The correct way to set the values

Set Obj=##Class(Data.Persistent).%New()
Set Obj.MPID=MPID
Set Obj.Name.FirstName=FirstName   ; <----Set Obj.Name.LastName=LastName     ; <----Set tSC=Obj.%Save()
0
Smythe Smythee  Nov 17, 2022 to Julius Kavay

Hi ,

I gave the example of the scenario i am using in my code but i am getting  Invalid Oref error

"

ERROR <Ens>ErrException: <INVALID OREF>zDischarge+3^CUSTOM.SQL.TestUtil.1 -- logged as '-' number - @' Set Obj.Discharge.DischargeFlag=DischargeFlag'"

0