how to create one VALUELIST from a class parameters ?
Hello everyone!
I have an abstract class representing the possible inputs for an Enum field, in the following way:
Class system.dto.sector.SectorStatusEnum [ Abstract ] { Parameter Active = 1; Parameter Inactive = 2; Parameter Production = 3; Parameter Upkeep = 4; }
I need to create a persistent class referencing the abstract class in the status field, so that the result of the operation is the same as the example:
Class datas.TblSector Extends %Persistent { Property Description As %String( MAXLEN = 100 ) [ Required ]; Property Status As %String( VALUELIST=",1,2,3,4", DISPLAYLIST=", Active, Inactive, Production, Upkeep") [ Required ]; }
Can someone help me pls?
PARAMETER and DISPLAYLIST are both compiler directives and you can't mix them.
But you may workaround it by writing your own pair of DisplayToLogical / LogicalToDisplay ClassMethods for this property´.
Parameter Active = 1;
Parameter Inactive =2;
Parameter Production = 3;
Parameter Upkeep 4;
/// DISPLAYLIST = ", Active, Inactive, Production, Upkeep",
Property Status As %String(VALUELIST = ",1,2,3,4") [ Required ];
ClassMethod StatusDisplayToLogical(%val) As %String
{ Quit $case(%val,..#Active:1,..#Inactive:2,..#Production:3,..#Upkeep:4,:"") }
ClassMethod StatusLogicalToDisplay(%val) As %String
{ Quit $case(%val,1:..#Active,2:..#Inactive,3:..#Production,4:..#Upkeep,:"") }
Is there a function that returns a string or list with all the parameters of the class?
Not as string.
Parameters are stored as sub-object with the class object in %Dictionary.* classes.
And serve as Information for the code to be compiled.
not a built-in, but you can easily create one
Thanks !
Is possible to use the return of the Method to build the VALUELIST ?
Or other property with the same purpose?
Do I understand you right, you want to get the Value of a VALUELIST as a return value of a method? If yes, then the answer is yes.
And a few examples...
Alternatively, %Dictionary package macros can be used:
Also, you can find object from list without explicitly iterating the whole thing:
instead of:
Hi Davi,
A simplest way is creating a datatype class:
And use the datatype in your class:
Example:
Hello everyone !
I thank the help of all!
with everyone's help, it was possible to create a property with the same behavior as VALUE LIST from the parameters of a class.
below is the test code:
First create the abstraction
Second I created the class with the parameters, containing extension of the abstract class
Create a datatype class referencing a parameter class in your property:
And finally create a Persistent class:
This architecture can be useful for future code maintenance, creating or changing new abstract classes
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue