Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
it was a simple example, my real one is using a callbackhandler. i've added the returnType to this simple example and returns "message was logged", i don't know if it actually executes the second function, i would expect to see "doSomething just called me" too
Copy link to clipboard
Copied
It's very difficult to diagnose if we don't know what code is actually failing.
You will not see "doSomething just called me" because that function has no returnType either and the calling function is not storing the result to return from it's call. I'm afraid we will need to see your actual code to be of any help. You can change any url, file system, usernames, passwords, databases, table names, etc in your code example that you post here.
Copy link to clipboard
Copied
if we can't make this simple example work, how are we gonna handle the other one? i don't want the first function to return anything, i just want it to call the second function, and that one, in turn, return a string. i've added Dan's suggestion, still nothing
<cfcomponent name="testfunc">
<cffunction name="doSomething" access="remote" output="false" returnType="string">
<cfset var firstMessage="message received from doSomething">
<cfscript>
logSomething(firstMessage);
</cfscript>
</cffunction>
<cffunction name="logSomething" access="remote" output="false" returnType="string">
<cfargument name="firstMessage" type="string" required="yes">
<cfreturn firstMessage>
</cffunction>
</cfcomponent>
Copy link to clipboard
Copied
i couldn't make this work, however, it turns out i don't have to. while "returning" a string that comes from a different function doesn't seem to be possible, my real code actually works, provided i call the second function BEFORE using the cfreturn in the first
however, the reason it wasn't working before, was my var name, which was "writeLog". turns out writelog is a reserved word, it's an actual CF function
it looks like it might be able to do what i'm doing in my second function, however it didn't work when i tried in a cfm page:
<cfscript>
function someLog() {
WriteLog(type="Info", file="myFile.log", text="someText");
}
</cfscript>
Copy link to clipboard
Copied
In addition to Miguel's answer, if you are going to do this:
logSomething(logThis);
Then the logSomething function needs an appropriate cfargument tag.