Trouble using cffunction

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  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. Similar Questions and Discussions

    1. cffunction problem
      Well I am having big problem with coldfusion functions. I have a function in my cfm page to parse xml. In that function I have couple of variables...
    2. CFFunction Date Argument
      Hi all! Here's the setup... In a cfc method: <cfargument name="myDate" type="date" required="no" default=""> In my calling cfm: <cfset...
    3. Problem with cffunction
      I am getting the following error when the site is on the production server, but it works fine on my local machine. Routines cannot be declared...
    4. UDFs vs cffunction
      Hi All, I'm very new to all this so sorry for the stupid questions and repeated topics etc. I find it easier to use UDFs than cffunctions...
    5. Calling a CFFUNCTION?
      I am working on a form that has 3 drop down selection boxes. What I need to have happen is this: Once the first selection (Category) is made, the...
  3. #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

  4. #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

  5. #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

  6. #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

  7. #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

  8. #7

    Default Re: Trouble using cffunction

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

Posting Permissions

  • You may not post new threads
  • You may 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