Question
· 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 = "") {
         quit
      }
   write !,"key: ", key,", Item: ",item
   }
   do p1.%Save()
   write ..p1.%GetParameter("myPropName")
   write !
}

}

I've visited:

(Using %Dictionary classes)

https://irisdocs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page...

(Class definition for %Dictionary.PropertyDefinition)

https://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?...

(DC article that might be a similar topic)

https://community.intersystems.com/post/how-set-property-parameters-cos

(Using Literal Properties)

https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY...

 

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).

 

Thanks.

Discussion (4)0
Log in or sign up to continue

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.