Discussion (6)2
Log in or sign up to continue

Hi @Phillip Wu

If you're create new object values. Means, The %New() - Creates a new instance of object and It invokes the user provided callback method "%OnNew()". You can define your properties if you want in that call back methods.

Class Backup.Task Extends %Persistent
{
Property TaskName As %String;
Property TaskDescription As %String;
Method %OnNew(pTaskName As %String, pTaskDescription As %String) As %Status
{
 	Set ..TaskName = pTaskName
 	Set ..TaskDescription = pTaskDescription
 	Return $$$OK
}

ClassMethod CreateNewTask()
{
	Set taskObj = ##Class(Backup.Task).%New("DailyBackup","Runs a daily backup")
	Set st = taskObj.%Save()
}

}

 If you want to fetch the values of already stored. You have to use the %OpenId(id) and pass the id to open the instance of the expected object and you can fetch the values

ClassMethod GetTaskDetails(taskId)
{
    Set taskObj = ##Class(Backup.Task).%OpenId(taskId)
    Set lastRunStatus = taskObj.LastRunStatus
}