For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Developing Applications Help / 

Passing parameters to methods

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

You pass parameters to a method in a CFC by using the cfinvoke tag, direct method invocations, or by passing parameters in a URL.

Passing parameters to methods by using the cfinvoke tag

When you use the cfinvoke tag, ColdFusion provides several methods for passing parameters to CFC methods:

  • As cfinvoke tag attributes, in name="value" format
  • In the cfinvoke tag argumentcollection attribute
  • In the cfinvoke tag body, using the cfinvokeargument tag

You can use any combination of these methods in a single invocation. If you use the same name in two or three of these methods, ColdFusion uses the value based on the following order of precedence:

  1. cfinvokeargument tags
  2. cfinvoke attribute name-value pairs
  3. argumentcollection arguments
Passing parameters by using attribute format

You can pass parameters in the cfinvoke tag as tag attribute name-value pairs, as the following example shows:

<cfinvoke component="authQuery" method="getAuthSecure"
lastName="#session.username#" pwd="#url.password#">

In the example, the parameters are passed as the lastName and pwd attributes.

Note: The cfinvoke tag attribute names are reserved and cannot be used for parameter names. The reserved attribute names are: component, method, argumentCollection, and returnVariable. For more information, see the CFML Reference.

Passing parameters in the argumentCollection attribute

If you save attributes to a structure, you can pass the structure directly using the cfinvoke tag's argumentCollection attribute. This technique is useful if an existing structure or scope (such as the Forms scope) contains values that you want to pass to a CFC as parameters, and for using conditional or looping code to create parameters.
When you pass an argumentCollection structure, each structure key is the name of a parameter inside the structure. 
The following example passes the Form scope to the addUser method of the UserDataCFC component. In the method, each form field name is a parameter name; the method can use the contents of the form fields to add a user to a database.

<cfinvoke component="UserDataCFC" method="addUser" argumentCollection="#Form#">

Passing parameters by using the cfinvokeargument tag

To pass parameters in the cfinvoke tag body, use the cfinvokeargument tag. Using the cfinvokeargument tag, for example, you can build conditional processing that passes a different parameter based on user input.
The following example invokes the corpQuery component:

<cfinvoke component="corpQuery" method="getEmp">
<cfinvokeargument name="lastName" value="Wilder">
</cfinvoke>

The cfinvokeargument tag passes the lastName parameter to the component method. 
In the following example, a form already let the user select the report to generate. After instantiating the getdata and reports components, the action page invokes the doquery component instance, which returns the query results in queryall. The action page then invokes the doreport component instance and uses the cfinvokeargument tag to pass the query results to the doreport instance, where the output is generated.

<cfobject component="getdata" name="doquery">
<cfobject component="reports" name="doreport">
<cfinvoke component="#doquery#" method="#form.whichreport#" returnvariable="queryall">
<cfinvoke component="#doreport#"method="#form.whichreport#">
<cfinvokeargument name="queryall" value="#queryall#">
</cfinvoke>

Passing parameters in direct method invocations

ColdFusion provides three methods for passing parameters to CFC methods in direct method invocations:

  1. You can pass the parameters the form of comma-separated name="value"entries, as in the following CFScript example:

    authorized = securityCFC.getAuth(name="Almonzo", Password="LauRa123");

     

  2. You can pass the parameters in an argumentCollectionstructure. The following code is equivalent to the previous example:

    argsColl = structNew();
    argsColl.username = "Almonzo";
    argsColl.password = "LauRa123";
    authorized = securityCFC.getAuth(argumentCollection = argsColl);

     

  3. You can pass positional parameters to a method by separating them with commas. The following example calls the getAuthmethod, and passes the name and password as positional parameters:

    authorized = securityCFC.getAuth("Almonzo", "LauRa123");

     

Note: For more information on using positional parameters and component methods in ColdFusion functions, see Creating user-defined functions.

Passing parameters in a URL

ColdFusion lets you pass parameters to CFC methods in a URL. To do so, you append the URL in standard URL query-string, name-value pair syntax; for example:

http://localhost:8500/CompanyQuery.cfc?method=getEmp&lastName=Adams

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices