Skip to main content
Inspiring
September 18, 2012
Question

calling a cffunction from another cffunction

  • September 18, 2012
  • 2 replies
  • 3024 views

i figured this would work, it doesn't throw an error but it doesn't create a log entry either. what am i doing wrong?

<cfcomponent>

<cffunction name="doSomething">

     <cfset var logThis="create a new log entry">

    <cfscript>

       logSomething(logThis);

    </cfscript>

</cffunction>

<cffunction name="logSomething">

     ... some code i know works...

     <cffile action="append" file="#localFile#" output="#txtVar#" addNewLine="yes"> 

</cffunction>

</cfcomponent>

thanks

This topic has been closed for replies.

2 replies

Inspiring
September 18, 2012

In addition to Miguel's answer, if you are going to do this:

logSomething(logThis);

Then the logSomething function needs an appropriate cfargument tag.

Miguel-F
Inspiring
September 18, 2012

It's hard to say what is wrong from the simple example given.  You can definitely call a function from within a function, no problem.  Are you sure no error is being thrown? 

ionAuthor
Inspiring
September 18, 2012

i've simplified it even more, returns "null" within the cfdiv

this is the cfc

<cfcomponent>

<cffunction name="doSomething" access="remote">

    <cfscript>

       logSomething();

    </cfscript>

</cffunction>

<cffunction name="logSomething">

    <cfreturn "doSomething just called me">

</cffunction>

</cfcomponent>

and this is a cfm using it:

<cfajaximport />

<cfdiv bind="cfc:testfunc.doSomething()"></cfdiv>

Miguel-F
Inspiring
September 18, 2012

Oh I thought you had just posted a simple example here.  Didn't know that was your actual cfc.  It is returning "null" to your div because you are not specifying a returntype from your functions.  If you want it to return something, try this:

<cffunction name="doSomething" access="remote" returnType="string">

    <cfscript>

       logSomething();

    </cfscript>

    <cfreturn "message was logged">

</cffunction>

<cffunction name="logSomething">

    <cfreturn "doSomething just called me">

</cffunction>