CFSCRIPT | |
Description | |
Encloses a code block that contains cfscript statements. | |
Category | |
Application framework tags, Other tags | |
Syntax<cfscript> cfscript code here </cfscript> |
|
See also | |
cfinvoke, cfmodule, CreateObject, Chapter 6, "Extending ColdFusion Pages with CFML Scripting," in Developing ColdFusion MX Applications | |
History | |
ColdFusion MX: | |
|
|
Usage | |
Performs processing in CFScript. This tag uses ColdFusion functions, expressions, and operators. You can read and write ColdFusion variables within this tag. | |
For a detailed description of the CFScript scripting language, including documentation of CFScript statements and the CFScript equivalents of CFML tags, see Chapter 6, "Extending ColdFusion Pages with CFML Scripting," in Developing ColdFusion MX Applications. | |
You can use this tag to enclose a series of assignment statements that would otherwise require cfset statements. |
Caution: | If you code a cftry/cfcatch block within this tag using an exception's Java class name, you must provide the fully-qualified class name. |
You cannot use some ColdFusion reserved words in this tag. You cannot put a user-defined function whose name begins with any of these strings within this tag:
You cannot use the elseif construct within a cfscript tag. You can use code such as the following:
else if ( condition ) { ... }
The following example shows how to invoke a component object with the cfscript tag, using ordered arguments:
<cfscript> quote = createObject( "component", "nasdaq.quote" ) ; <!--- invocation using ordered arguments ---> res = quote.getLastTradePrice( "macr" ) ; </cfscript>
The following example shows how to use an attribute collection within the cfscript tag to pass parameters when invoking a component object. An attribute collection is a structure in which each key corresponds to a parameter name and each value is the parameter value passed for the corresponding key.
<cfscript> stArgs = structNew(); stArgs.translationmode = "en_es"; stArgs.sourceData= "Hello world, friend"; </cfscript> ... <cfinvoke webservice = "http://www.xmethods.net/sd/2001/BabelFishService.wsdl" method = "BabelFish" argumentCollection = "#stArgs#" returnVariable = "varName" > <cfoutput>#varName#</cfoutput>
In this example, the structure is created in a cfscript block, but you can use any ColdFusion method to create the structure.
<cfscript> ws = CreateObject("webservice", "http://www.xmethods.net/sd/2001/BabelFishService.wsdl"); xlatstring = ws.BabelFish("en_es", "Hello world, friend"); writeoutput(xlatstring); </cfscript>
For more information, see Chapter 32, "Using Web Services," in Developing ColdFusion MX Applications.
<p>This simple example shows variable declaration and manipulation. <cfif IsDefined("form.myValue")> <cfif IsNumeric(form.myValue)> <cfset x = form.myValue> <cfscript> y = x; z = 2 * y; StringVar = form.myString; </cfscript> <cfoutput> <p>twice #x# is #z#. <p>Your string value was: <b><I>#StringVar#</i></b> </cfoutput> <cfelse>