Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Some advanced CFSCRIPT issues

Status
Not open for further replies.

deepatpaul

Programmer
Jul 7, 2004
57
US
How can I return the value of a UDF, not as a literal variable's value, but as a placeholder? Example:

<cfscript>
function isUDF(var1)
errorMsg = "";
{
// do conditionl testing for first variable entered
if var1 != 'foo' (errorMsg = "Custom error 1")
else if var1 == 'foo' (errorMsg = "Custom error 2")
}
// If 2nd argument is passed, then check for return error value, otherwise return boolean.
if (arraylen(Arguments) gt 1)
{
"#arguments[2]#" = errorMsg;
return #arguments[2]#;
// return the value of errorMsg passed as #arguments[2]#
} else {
// otherwise, return boolean value
return true;
}
</cfscript>

<cfif not IsUDF(variables.foo,"variables.placeholder")>
#variables.placeholder#
</cfif>

Where the first variable returns a boolean value, and the second returns a text value of a specified error message. Right now, i get an error saying the 2nd variable can't be converted to boolean, but I don't want boolean for it.
 
according to live docs:

A function can use and change any variable that is available in the calling page, including variables in the caller's Variables (local) scope, as if the function was part of the calling page. For example, if you know that the calling page has a local variable called Customer_name (and there is no function scope variable named Customer_name) the function can read and change the variable by referring to it as Customer_name or (using better coding practice) Variables.Customer_name. Similarly, you can create a local variable inside a function and then refer to it anywhere in the calling page after the function call. You cannot refer to the variable before you call the function.

so i tested it and it works.

<cfscript>
function isUDF(var1){
udfMsg = "";
if(var1 eq "foo"){
udfMsg = "Sorry foo is not the right answer";
}
return true;
}
</cfscript>
<html>
<body>
<cfoutput>#isudf("foo")# : #udfMsg#</cfoutput>
</body>
</html>


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
The example I'm using isn't accurate to how the calling template works. The actual source code is calling it as a java package, remote from the folder of the caller. Should it still work all the same?
 
um i'm not sure, sorry. best thing to do is try it i guess.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top