Written by

Software Developer at J2 Interactive
Question Rizmaan Marikar · 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?

Comments

Suman Samanta · Sep 22, 2019

did you try xcute . Its used to execute strings .

0
Rizmaan Marikar  Sep 22, 2019 to Suman Samanta

thanks a mil,  xecute  worked

0
Robert Cemper · Sep 22, 2019

almost done

do @aa

But 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, ...

0
Vitaliy Serdtsev · Sep 23, 2019

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>

0