Run a cache expression stored in a variable
Hi All,
I have a class method, this can be any cache expression to execute (usually a class / method and args) and and args stored in a variable, for example;
set aa = "##Class(Utils.Test).Run(1,2,3)" do aa
I tried using $classmethod(class,method,args..), by extracting the values but sometimes there can be no arguments, or arguments such as ;
("2019-01-01","1,2,3,4")
which causes issues while running the $classmethod, (i am using $P to extract the Class, Method and args).
Is there any simpler way of doing this?
Discussion (4)0
Comments
did you try xcute . Its used to execute strings .
thanks a mil, xecute worked
almost done
do @aaBut be aware that variables you pass to your method are either explicit as in your example
or are variables in global scope. eg. %par1, %par2, ...
Class dc.test Extends %RegisteredObject
{
ClassMethod Run(
a,
b)
{
w $$$FormatText("a=%1, b=%2",$g(a,"<null>"),$g(b,"<null>")),!
}
ClassMethod Test()
{
s cName="dc.test",
mName="Run",
args=2,
args(1)="2019-01-01",
args(2)="1,2,3,4"
d $classmethod(cName,mName,args...)
k args
s args=1,
args(1)=77
d $classmethod(cName,mName,args...)
k args
s args=2,
args(2)=33
d $classmethod(cName,mName,args...)
k args
s args=""
d $classmethod(cName,mName,args...)
}
}
Result:
USER>d ##class(dc.test).Test()
a=2019-01-01, b=1,2,3,4
a=77, b=<null>
a=<null>, b=33
a=<null>, b=<null>