Question
· Sep 22, 2019

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
Log in or sign up to continue
Class dc.test Extends %RegisteredObject
{

ClassMethod Run(
  a,
  b)
{
  w $$$FormatText("a=%1, b=%2",$g(a,"<null>"),$g(b,"<null>")),!
}

ClassMethod Test()
{
  cName="dc.test",
    mName="Run",

    args=2,
    args(1)="2019-01-01",
    args(2)="1,2,3,4"
    
  d $classmethod(cName,mName,args...)
  
  args
  args=1,
    args(1)=77
  d $classmethod(cName,mName,args...)

  args
  args=2,
    args(2)=33
  d $classmethod(cName,mName,args...)

  args
  args=""
  d $classmethod(cName,mName,args...)
}

}

Result:

USER>##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>