How do you call a cffunction in a cfc from another cfm page using cfscript?

isurfbecause picture isurfbecause · Jul 11, 2012 · Viewed 12.9k times · Source

I have a test.cfm page and would like to call a cfc with a <cffunction> named errorEmail using <cfscript> from that page (test.cfm) instead of

<cfinvoke component = "#cfcPath#" method = "errorEmail" returnVariable = "myReturn" 
    description = "get list of projman">
</cfinvoke> 

I have tried:

<cfscript>
   errorEmail(cfcPath);
</cfscript>

Answer

Evik James picture Evik James · Jul 11, 2012

I do this all the time.

1) Create the object:

<cfscript>
    // CREATE OBJECT 
    TheCFC = createObject("component", "thecfc");
</cfscript>

2) Call the function:

<cfscript>
    // CALL THE FUNCTION
    SomeVariable = TheCFC .theFunction();
</cfscript>

Your version would look like this

<cfscript>
    // CREATE OBJECT 
    TheObject = createObject("component", "cfcPath");
    // CALL THE FUNCTION
    myReturn = TheObject.errorEmail();
</cfscript>