User Guide

cfscript 305
You cannot use the elseif construct within a cfscript tag. You can use code such as the
following:
else if ( condition )
{
...
}
Exception handling with the cfscript tag
To handle exceptions with this tag, use
try and catch statements, which are equivalent to the
cftry and cfcatch tags. For each try statement, you must have a catch statement. In the catch
block, the variable
exceptionVariable contains the exception type. This variable is the
equivalent of the
cfcatch tag built-in variable cfcatch.Type. For more information, see
Chapter 6, “Extending ColdFusion Pages with CFML Scripting,” in Developing ColdFusion MX
Applications.
Invoking ColdFusion components with the cfscript tag
CFScript invokes component methods using the
createObject function.
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.
Consuming web services with the cfscript tag
The following example shows how to consume a web service with the
cfscript tag. You use the
CreateObject function to connect to the web service.
<cfscript>
ws = CreateObject("webservice",
"http://www.xmethods.net/sd/2001/BabelFishService.wsdl");