<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFSCRIPT</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFSCRIPT</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Encloses a code block that contains cfscript statements.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Application framework tags, Other tags
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cfscript&gt; 
   cfscript code here 
&lt;/cfscript&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfinvoke, cfmodule, CreateObject; Chapter&#160;6, "Extending ColdFusion Pages with CFML Scripting" in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX: 
</p>
<ul>

<li>Changed how to invoke component methods: this tag can now invoke component methods, using the CreateObject function</li>

<li>Changed use of reserved words: you cannot use ColdFusion reserved words within this tag</li>

<li>Added the try and catch statements.</li>
</ul>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
Performs processing in CFScript. This tag uses ColdFusion functions, expressions, and operators. You can read and write ColdFusion variables within this tag. 
</p>

<p>
For a detailed description of the CFScript scripting language, including documentation of CFScript statements and the CFScript equivalents of CFML tags, see Chapter&#160;6, "Extending ColdFusion Pages with CFML Scripting" in ColdFusion MX Developer's Guide.
</p>

<p>
You can use this tag to enclose a series of assignment statements that would otherwise require cfset statements.
</p>
<table>
  <tr valign="top">
    <td width="30"><strong>Caution: </strong></td>
    <td>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. </td>
  </tr>
</table>
<p>
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: 
</p>
<ul>

<li>cf</li>

<li>cf_</li>

<li>_cf</li>

<li>coldfusion</li>

<li>coldfusion_</li>

<li>_coldfusion</li>
</ul>

<p>
You cannot use the elseif construct within a cfscript tag. You can use code such as the following:
</p>
<pre>else if ( condition )
{
...
}
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Exception handling with the cfscript tag</span>
<p>
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&#160;6, "Extending ColdFusion Pages with CFML Scripting" in ColdFusion MX Developer's Guide.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Invoking ColdFusion components with the cfscript tag</span>
<p>
CFScript invokes component methods using the CreateObject function. 
</p>

<p>
The following example shows how to invoke a component object with the cfscript tag, using ordered arguments:
</p>
<pre>&lt;cfscript&gt;
quote = CreateObject( &quot;component&quot;, &quot;nasdaq.quote&quot; ) ;
&lt;!--- Invocation using ordered arguments. ---&gt;
res = quote.getLastTradePrice( &quot;macr&quot; ) ;
&lt;/cfscript&gt;
</pre>
<p>
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. 
</p>
<pre>&lt;cfscript&gt;
   stArgs = structNew();
   stArgs.translationmode = &quot;en_es&quot;;
   stArgs.sourceData= &quot;Hello world, friend&quot;;
&lt;/cfscript&gt;
...
&lt;cfinvoke
   webservice = &quot;http://www.xmethods.net/sd/2001/BabelFishService.wsdl&quot;
   method     = &quot;BabelFish&quot;
   argumentCollection = &quot;#stArgs#&quot;
   returnVariable = &quot;varName&quot;   &gt; 
&lt;cfoutput&gt;#varName#&lt;/cfoutput&gt;   
</pre>
<p>
In this example, the structure is created in a cfscript block, but you can use any ColdFusion method to create the structure. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Consuming web services with the cfscript tag</span>
<p>
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.
</p>
<pre>&lt;cfscript&gt;
   ws = CreateObject(&quot;webservice&quot;, 
            &quot;http://www.xmethods.net/sd/2001/BabelFishService.wsdl&quot;);
   xlatstring = ws.BabelFish(&quot;en_es&quot;, &quot;Hello world, friend&quot;);
   writeoutput(xlatstring);
&lt;/cfscript&gt;
</pre>
<p>
For more information, see Chapter&#160;36, "Using Web Services" in ColdFusion MX Developer's Guide.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;p&gt;This simple example shows variable declaration and manipulation.
&lt;cfif IsDefined(&quot;form.myValue&quot;)&gt;
   &lt;cfif IsNumeric(form.myValue)&gt;
      &lt;cfset x = form.myValue&gt;
      &lt;cfscript&gt;
         y = x;
         z = 2 * y;
         StringVar = form.myString;
      &lt;/cfscript&gt;
   &lt;cfoutput&gt;      &lt;p&gt;twice #x# is #z#.
      &lt;p&gt;Your string value was: &lt;b&gt;&lt;I&gt;#StringVar#&lt;/i&gt;&lt;/b&gt;   &lt;/cfoutput&gt;
&lt;cfelse&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>

  </body>
</html>
