Professional Web Applications Themes

Trouble using cffunction - Coldfusion - Advanced Techniques

Hi, I'm trying to use cffunction for the first time. My function looks like this: <cffunction name="getTitle"> <cfargument name="lineitem"> <cfset var ret_title = ""> <cfset var id = getArtId(lineitem)> <cfquery name="gettitle" datasource="#Application.DSN#" username="#Application.dsn_username#" password="#Application.dsn_password#" cachedwithin="#CreateTimeSpan(0,1,0,0)#"> SELECT title, description FROM Artwork WHERE artwork_id = '#id#' </cfquery> <cfif gettitle.recordcount> <cfset ret_title = "#gettitle.title#"> </cfif> <cfreturn ret_title> </cffunction> My call to it looks like this: <cfset title = getTitle(lineitem)> And the error I get looks like this: Entity has incorrect type for being called as a function. The symbol you have provided getTitle is not the name of a function. What am I ...

  1. #1

    Default Trouble using cffunction

    Hi,

    I'm trying to use cffunction for the first time. My function looks like this:

    <cffunction name="getTitle">
    <cfargument name="lineitem">
    <cfset var ret_title = "">
    <cfset var id = getArtId(lineitem)>

    <cfquery name="gettitle" datasource="#Application.DSN#"
    username="#Application.dsn_username#" password="#Application.dsn_password#"
    cachedwithin="#CreateTimeSpan(0,1,0,0)#">
    SELECT title, description
    FROM Artwork
    WHERE artwork_id = '#id#'
    </cfquery>

    <cfif gettitle.recordcount>
    <cfset ret_title = "#gettitle.title#">
    </cfif>

    <cfreturn ret_title>
    </cffunction>

    My call to it looks like this:

    <cfset title = getTitle(lineitem)>


    And the error I get looks like this:

    Entity has incorrect type for being called as a function.
    The symbol you have provided getTitle is not the name of a function.


    What am I not understanding here?

    Jtra Guest

  2. #2

    Default Re: Trouble using cffunction

    First you need to reference the object on the page:

    <CFOBJECT COMPONENT="directory1.directory2.titles" NAME="titleObj">

    The "directory1.directory2.titles" is the path to the actual cfc file. (In
    this example, the file is named titles.cfc) Which would be located in
    /directory1/directory2/titles.cfc.

    Second, you call the function like this:
    <cfoutput>#titleObj.getTitle()#</cfoutput>

    If your CFC has arguments, it would look like this:
    <cfoutput>#titleObj.getTitle(EMPLOYEEID='12345') #</cfoutput>

    JC

    J.C. Guest

  3. #3

    Default Re: Trouble using cffunction

    So my cffunction has to be part of a component? I thought with MX7 it didn't have to be? I'm not using a component.
    Jtra Guest

  4. #4

    Default Re: Trouble using cffunction

    > <cffunction name="getTitle">

    This creates a variables.getTitle, which hold your function.

    > <cfquery name="gettitle" datasource="#Application.DSN#"
    This ALSO creates variables.getTitle... overwriting your function.

    So it'll work fine the first time, but thereafter the function will have
    replaced itself with a query, so can't call it again.

    You need to VAR *all* your variables. including your queries.

    <cfset var getTitle = queryNew("")>

    --

    Adam
    Adam Cameron Guest

  5. #5

    Default Re: Trouble using cffunction

    I've never used cffunction outside of a component, plus I'm not using MX7. So,
    I can't answer your question. I do know that using a component works like a
    champ. If you get stuck, I highly recommend using them. Reusing code rocks!

    JC

    J.C. Guest

  6. #6

    Default Re: Trouble using cffunction

    you can also use it like this.


    <cffunction name="getName" returntype="string">
    <cfargument name="temp" default="">
    <cfset retValue = "">
    <cfset id = arguments.temp>
    <cfquery datasource="itphonelist" name="q">
    select * from menu where id = #id#
    </cfquery>

    <cfif q.recordcount>
    <cfset retValue = q.displayname>
    </cfif>

    <cfreturn retValue>

    </cffunction>


    <cfoutput>#getName(1)#</cfoutput>

    trjlove Guest

  7. #7

    Default Re: Trouble using cffunction

    Thank you Adam!!!! I never would have figured that out :)
    Jtra Guest

Similar Threads

  1. cffunction problem
    By bongobuda in forum Macromedia ColdFusion
    Replies: 3
    Last Post: June 16th, 05:16 PM
  2. CFFunction Date Argument
    By SharonMCoupe in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 18th, 05:39 PM
  3. Problem with cffunction
    By Jfill in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: May 2nd, 01:57 PM
  4. UDFs vs cffunction
    By jammln in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 29th, 03:23 PM
  5. Calling a CFFUNCTION?
    By jce1975 in forum Macromedia ColdFusion
    Replies: 2
    Last Post: March 3rd, 06:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139