Skip to main content

Object Methods

The ObjectScript.Person class also provides some inherited methods for your use:

  • %New() creates a new Person object in your process.

  • %OpenId() loads a saved persistent Person object into your process. %OpenId() automatically supports both exclusive and shared locks.

  • %Save() verifies the data in a Person object in your process, and if the data verifies correctly, saves the data. If the data is invalid, %Save() returns an error. A %Save() of an object is automatically performed as a transaction.

To create new Person objects, you use %New(), set the data using object.property syntax, and %Save(). For editing existing objects, you use %OpenId(), update the data, and %Save().

Here are some examples. The first few lines create a new person object and save it. The next few lines open an existing Person object whose ID number is 2 and display its data. Set person to "" to destroy the person object in your process (but not the persistent copy).

Terminal


USER>set person = ##class(ObjectScript.Person).%New()

USER>set person.Name = "Smith,John", person.Phone = "555-555-5555", person.DOB = $zdateh("8/8/88")

USER>do person.%Save()

USER>set person = ""

USER>set person = ##class(ObjectScript.Person).%OpenId(2)

USER>write person.Name
Smith,Mary
USER>write person.Phone
777-777-7777
USER>write $zdate(person.DOB)
09/09/99
USER>set person = ""

USER>
FeedbackOpens in a new tab