Written by

Question Phillip Wu · Feb 9

Objectscript get classs property error

Hi,

I'm trying to get a property from a class but I get an error:

SET status=##CLASS(Backup.Task).LastRunStatus
^
<CLASS PROPERTY>
 

Can someone please tell me the correct way to get the property?

The property is dexcribed here:

https://docs.intersystems.com/irislatest/csp/documatic/%25CSP.Documatic…

Thanks in advance.

Comments

Yuji Ohata · Feb 9

Hi, Phillip

The properties should be obtained from the instantiated variable.
Instantiate Backup.Task using methods like %New() or OpenId() before retrieving the properties.

0
Phillip Wu  Feb 10 to Yuji Ohata

If I understand this correctly, if I want to define a new backup task called bt1:
set bt=##class(Backup.Task).%New('bt1')

Then I can get the properties:
 

w bt.LastRunStatus

w bt.Name
bt1
Is this correct?

0
Ashok Kumar T  Feb 10 to Phillip Wu

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
}
0
Enrico Parisi  Feb 10 to Ashok Kumar T

Backup.Task is a system class located in %SYS, I'm not sure if creating a Backup.Task in another namespace (hopefully!!) address his issue.

0
Enrico Parisi · Feb 10

That property contains the last run status of a specific task, so first you need to know what task you are interested and then open that task and get the last status, like:

Set BckTask=##class(Backup.Task).%OpenId("FullDBList")
Set status=BckTask.LastRunStatus

0
Phillip Wu  Feb 10 to Enrico Parisi

Thanks to everyone for all your information!

0