Required (Property Syntax and Keyword)
To specify that the property is required, use the following syntax:
Property name As classname [ Required ];
Otherwise, omit this keyword or place the word Not immediately before the keyword.
For a persistent class, this keyword specifies that the property must be given a value before the containing object can be stored to disk; an error occurs if the property does not have a value.
If a property is of type %StreamOpens in a new tab, the stream cannot be a null stream. That is, the stream property is considered to have a value if the %IsNull() method returns 0.
For a class that extends %XML.AdaptorOpens in a new tab, this keyword affects the corresponding XML schema. If a property is marked Required, then the corresponding element in the schema does not have minOccurs="0" and is thus considered required. See Projecting Objects to XML. Note that in this case, the class does not have to be a persistent class. XML schema validation occurs when InterSystems IRIS reads an XML document; see Using XML Tools.
In a subclass, you can mark an optional property as required, but you cannot do the reverse.
If a property is marked as both read-only and required, note the following difference in behavior between object access and SQL access:
When you save the object, InterSystems IRIS does not validate the property. This means that InterSystems IRIS ignores the Required keyword for that property.
When you insert or update a record, InterSystems IRIS does consider the Required keyword for the property.
If you omit this keyword, the property is not required.
“Property Definitions” in this book
“Defining and Using Literal Properties” in Defining and Using Classes
“Working with Collections” in Defining and Using Classes
“Working with Streams” in Defining and Using Classes
“Defining and Using Object-Valued Properties” in Defining and Using Classes
“Defining and Using Relationships” in Defining and Using Classes
“Introduction to Compiler Keywords” in Defining and Using Classes