Skip to main content
September 11, 2008
Question

How to Pass Variable to funcion in CFC

  • September 11, 2008
  • 1 reply
  • 329 views
I have a "two related selects" in a form that makes use of a CFC. It works well for what it currently does: Choosing an account in the first select and then choosing the related sales rep in the second select. Please note that the query that brings back the accounts for the first select just brings back ALL accounts.

I now need to pass a variable to the CFC so that the first account initially selected will be dynamic, but I am not quite sure the best way to do this... I am fairly new to CFC's.

Below is my code for the selects and the first part of the code from my CFC. The CFC code has been updated to include an argument to which I am trying to pass a variable:

<!--- Select 1 --->
<cfselect name="Partners"
bind="cfc:getPartners_dev.getAccounts()"
bindonload="true" tooltip="Select Account Partner"/>

<!--- Select 2 --->
<cfselect name="Contacts"
bind="cfc:getPartners_dev.getUsers({Partners})" tooltip="Select Partner Rep" onError="" style="width:200px;"
/>

CFC:


<!--- Get array of Partners --->
<cffunction name="getAccounts" access="remote" returnType="array">
<cfargument name="accountID" type="string" required="no">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(2)>
<cfset var i=0>

<cfset data = oSF.queryObject("Select ID, Name from

Account
where (type = 'New' or type = 'Old'')
and accountID='#arguments.accountID#'
order by name").results />



    This topic has been closed for replies.

    1 reply

    Inspiring
    September 12, 2008
    There are several ways. This is my favourite.

    args = StructNew();
    args.var1 = "something";
    args.var2 = "something else";
    etc

    <cfselect name="Partners"
    bind="cfc:getPartners_dev.getAccounts(argumentcollection=args)"
    bindonload="true" tooltip="Select Account Partner"/>