Cache object creation(How to get a input to user)

Below object creation is correct or not .Suppose wrong as how to get the values to user.

Set Name=##class(Example.Team1).%New()
"enter your name :",Name.EmpName.
"enter your address:",Name.Address
"Enter your Phone number:",Name.PhoneNo
"Enter Your Id:",Name.id
set status = Name.%Save()

Answers

You can only read into simple local variables, so it should be like:

set Name=##class(Example.Team1).%New()
read "enter your name :", NameStr
set Name.EmpName = NameStr

There are also utility prompt methods, see %Library.Prompt class. For example GetString method supports object properties:

set Name=##class(Example.Team1).%New()
do ##class(%Library.Prompt).GetString("enter your name", Name.EmpName)

The code you supplied above doesn't compile correctly in Studio, so it looks like you can't read directly to a property of an object directly.  In your case, I would try something like this:

 

Set Name=##class(Example.Team1).%New()
read "Enter your name: ",nameinput
set Name.Name = nameinput
set status = Name.%Save()

 

 

There may be other ways of getting input into an object property, but this is one of the easiest.