Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

coldfusion

cfc

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>
like image 638
isurfbecause Avatar asked Jul 11 '12 16:07

isurfbecause


1 Answers

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>
like image 55
Evik James Avatar answered Dec 04 '22 08:12

Evik James