Brain blank apparently. ```someData = cfinvoke(com...
# cfml-general
d
Brain blank apparently.
Copy code
someData = cfinvoke(component="dotPathToService", method="someMethod", someArg="foo");
That throws the error "Variable CFINVOKE is undefined." CFDocs says cfinvoke has existed since cf6, it's documented by Adobe too. I most often use createObjectI) then call the methods I want on that object, but this is a one-off call, won't need the service again, so I thought this should do it, but I guess I'm missing something dumb. Or maybe that error is erroneous?
j
I think if you're passing in a single argument, it needs to be in curly braces following the cfinvoke statement - I put example 1 from the Adobe page into cfscript.me and it came out with this (apart from a comment about a lucee bug):
cfinvoke( returnVariable="res", method="getLastTradePrice", component="nasdaq.quote" ) {
cfinvokeargument( name="symbol", value="macr" );
}
d
Ugh, if that's the real syntax I'll pass, and use the createObject() version with a normal method call. Pfft. Thanks.
a
Why would you even start trying to use
cfinvoke
when you could just go
someData = new dotPathToService().someMethod(someArg="foo")
. Why add all the "generic tags in script" bloat?
👍 1
Also cfdocs is misleading here.
<cfinvoke>
was added in CFMX6, but the generic tags-in-script syntax was only introduced in CF11, and even then it was only added where there was not already a CFScript equivalent, which there already is:
invoke
. In your case, you'd write:
Copy code
someData = invoke("dotPathToService", "someMethod", {someArg="foo"});
But just... don't. Just use
new
and chain the method call.