John Kumpf · Apr 23, 2019

How do I create a custom Property Parameter?

Here's my current attempt:

Class Testing.PropertyParameters Extends %RegisteredObject
Property p1 As %String(MAXLEN = 5, myPropName = "myPropValue");
Method test()
   set ..p1 = 10
   //write ..p1.Parameters

   set p1 = ##class(%Dictionary.PropertyDefinition).%OpenId("Testing.PropertyParameters||p1")
   zwrite p1
   do p1.Parameters.SetAt("myPropValue", "myPropName")
   set key = ""
   for {
      set item = p1.Parameters.GetNext(.key)
      if (key = "") {
   write !,"key: ", key,", Item: ",item
   do p1.%Save()
   write ..p1.%GetParameter("myPropName")
   write !


I've visited:

(Using %Dictionary classes)

(Class definition for %Dictionary.PropertyDefinition)

(DC article that might be a similar topic)

(Using Literal Properties)


I am successfully opening the property definition in that code, and I can use:

select * from %Dictionary.PropertyDefinition where Name [ 'p1'

in the same namespace to view that definition.  I'm even successfully updating the Parameters list of that PropertyDefinition object.  Still, things don't seem to work.  I need to delete the myPropName part of the property definition, but then after I compile and click back into Studio, it repopulates the prop definition with that (probably getting it from the property definition in the db, which I changed).





1 0 4 244
Log in or sign up to continue


Why do you want to achieve that?

You need custom datatype for that, defining your parameters:

Class Testing.String Extends %String
Parameter myPropName;

And use that as a property type:

Class Testing.PropertyParameters Extends %RegisteredObject
Property p1 As Testing.String(MAXLEN = 5, myPropName = "myPropValue");

Still, please tell us your use case.

I'm building classes which contain representations of REST resources.  For example, a full (likely for administrators) representation of the "person" resource might contain all fields, and all of them are writable.  A limited (maybe authenticated, but non admin) representation might contain most fields, and some like name and email are writable, but others like employment status are not.  A minimal (maybe for unauthenticated users) representation would contain only a few, read-only fields.

The property parameters would be things like the name for the property we use in the JSON, whether the field is writable, other flags regarding how to represent relationships or object properties, etc.

I think what I'm imagining is very similar to the %XML.PropertyParameters class used by %XML.Adaptor

(If you're probably wondering why I didn't include all this in my original post, I've been discussing it with Tim Leavitt and my ideas are a lot more formulated than they were 2 hours ago.  I suspect that an analogous architecture to what's used with XML will work well.)

You can do it with a special property class. Here's how it works:

Class Testing.PropertyClass
Parameter myPropName;

Class Testing.MyPersistentClass Extends %RegisteredObject  [ PropertyClass = Testing.PropertyClass]
Property p1 As %String(MAXLEN = 5, myPropName = "myPropValue");

But I recommend you to check RESTForms project (part1, part2), which sounds like what you're doing -automatic REST interface for persistent  classes.

It also defines property class for similar purposes.

Thanks a lot.  This is almost definitely what I'm looking for.