invoke

Invokes an object method and returns the result of the invoked method.

invoke(instance, methodName [, arguments]) → returns any

Argument Reference

instance string
Required

Name or instance of a CFC or an instance of a Java, .NET, COM or CORBA object to instantiate. For a CFC, it can be an empty string when invoking a method within the same ColdFusion page or component.

methodname string
Required

The name of the method (or operation for webservice) to invoke.

arguments any

An array of positional arguments or a struct of named arguments to pass into the method.

Examples
Sample code invoking the invoke function

Invokes the size method on a new HashMap object, which should return 0

invoke(createObject("java", "java.util.HashMap"), "size")

Expected Result: 0

Invokes the method named 'test' on the component Test.cfc with one parameter

obj = createObject("component", "Test");
invoke(obj, "test", {parameter="Test Data"});

Invokes the method named 'test' on the webservice Test.cfc with one argument

obj = createObject("webservice", "https://example.com/test.cfc?wsdl");
invoke(obj, "test", {argument1="Test Data"});

Invokes the method named 'test' on the webservice Test.cfc with multiple arguments

obj = createObject("webservice", "https://example.com/test.cfc?wsdl");
invoke(obj, "test", {argument1="Test Data", argument2="More Data", argument3="Still More Data"});

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub