Execute stored functions at run-time - intersystems-cache

I am trying to retrieve stored functions from a table and have them executed at run-time.
Ex MyTableFieldValue contains:
$PARAMETER(MyClass,MyParameterName)
Where MyTableFieldValue is a field value in a table called MyTable.
MyParameterName value in class MyClass is actually "ThisParameter"
I want to do this:
Set parameterName = MyTableFieldValue
Where parameterName should contain "ThisParameter".
Instead it contains
$PARAMETER(MyClass,MyParameterName).
How do I force cache to actually evaluate what is in MyTableFieldValue ?

If data in your table is not user-editable you can use indirection to calculate your value as described in documentation
http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCOS_operators#GCOS_operators_indirection_arg
In your example it will look like
Set #("parameterName = "_MyTableFieldValue)
However this is insecure if users can change data in your table, because they can execute pretty much any code this way. In that case, you should parse the string, find your class name and parameter name, and run $parameter function call explicitly.

Related

Specification builder doesn't recognize transient properties

I'm trying to implement specification in one of my use cases.
As u can see in the function dateValueBetween, I'm trying to get from the root the transient property valueDate. But when calling this service with real data it give the error downside.
My original problem was how to call the builder.between method but the value I have is a String value and need to be parsed.
but it seems that the first argument need to be a property of the table and not a function.
How can I achieve my goal?

Passing complex object as parameter to sub-stack

I want to pass the output of a custom resource, which is an array of objects, as parameter to a sub-stack. An example of what I want to pass as parameter to the child stack is :
[
{"Role":"Role1","IdentifierType":"Prefix","Identifiers":"Bucket1"}
{"Role":"Role2","IdentifierType":"Prefix","Identifiers":"Bucket2"}
]
How do I pass this to the sub-stack? I tried declaring the parameter in the child stack as String, and later as CommaDelimitedList. Both the times, the stack gave an error: "Value of property Parameters must be an object with String (or simple type) properties"
As I know until now, there is not way to pass complex objects as a result of of stack execution. Like the message say, the outputs need to be string or single types (integer and boolean in case of cloudformation).
Without more information is hard to help you with alternatives, but let's assume that your Custom Resource is based on lambda. And let's assume that you have control about the code of your Custom Resource. If this is the case you can:
Send the resource identification of your custom resource as a parameter for your nested stack;
Inside nested stack, invoke the lambda function again with the resourceId as a parameter;
Change the lambda code to check for a new parameter for the resourceId (inside the ResourceParameters, not inside the Common Resource Id sent by CloudFormation).
If the parameter is not empty (or not a defined value passed on the first invocation) respond with the old values (you must have a way to keep this values in some place or check then in runtime.);
Change the lambda code to do not take action in the update/deletion is case of invocation by the nested stack (with the resourceId parameter).
Again, is hard to think in alternatives without more info about your specific problem. But use this response as a food for thought.

How can I get a VLAX-OBJECT from an ads_name type

I am using entget function in order to get all the properties of a certain object. So I have the table of dotted pairs that describe the properties of the object but now I want to use the VLAX-OBJECT functions, such as VLAX-COPY or VLAX-MOVE. So I need to convert it from the ads_name type to VLAX-OBJECT type but I can not handle to do it. Can you suggest any Idea to do it please?.
You can use the vlax-ename->vla-object function to get the VLAX object from the entity name

Scala how to get object property value given name of property in string?

I wondering how to get object property value given name of property in string in Scala? I saw examples when you get all fields of object using Reflection and iterate over it. But is it possible to call it without iteration? Or may be there is a way to pass object.field to another function without evaluation and evaluate it there and return result?
Kolmar comment give me right direction to call by name function.

How to set up classes

i am an engineering student enrolled in computer programming trying to understand a practice assignment for an upcoming lab and was wondering if someone could help me with this step of my program, Step: using The init method for the class takes the first formal parameter self and a list of [x, y] pairs v and stores the list as a class instance variable
It sounds like you are using Python, but next time you post a question, make sure you specify that and tag your question as such. You are looking for something like the following code:
class MyClassName(object):
def __init__(self, pairs):
self.pairs = pairs
Let's look at this line by line:
class MyClassName(object):
The first line declares a class called MyClassName. It extends object, which is not super important to understand right now, but is basically saying that MyClassName is a particular type of object.
def __init__(self, pairs):
The second line creates a function called __init__ which will be called when you instantiate an object of type MyClassName. This line also declares what parameters it takes. It sounds like you already know that the first argument has to be self, and the second parameter, pairs, is the list of [x,y] pairs. In python, we don't need to specify what type these parameters are, so we need only to name them (Some languages would require us to specify that pairs is going to be a list of pairs).
self.pairs = pairs
Now all we have to do is set the instance variable. Inside a class, self refers to this particular instance of the object. In other words, every time we create a variable of type MyClassName, the self keyword will refer to that particular instance of the object, rather than to all instances of MyClassName. So in this case, self.pairs refers to the variable pairs in this particular instance of MyClassName. On the other hand, pairs simply refers to the argument passed into the function __init__.
So, to put all this together, we have defined a class called MyClassName, then defined the __init__ function, and in it, we set the instance variable self.pairs to be equal to the pairs variable passed into __init__.
Last, I'll give a quick example of how to instantiate MyClassName:
my_list = [(1,1),(2,4),(3,9),(4,16)]
my_instance = MyClassName(my_list)
Good luck!
[Edit] Also, I agree with the first comment on your question. You need to be more clear and verbose in exactly what you are trying to accomplish and not leave it up to guess work. In this case, I think I could tell what you were trying to do, but it may not always be clear.