Execute stored functions at run-time

119 Views Asked by At

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 ?

1

There are 1 best solutions below

0
On BEST ANSWER

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.