Skip to main content
Participating Frequently
December 4, 2008
Answered

Problem Calling Query in Custom Tag

  • December 4, 2008
  • 4 replies
  • 1173 views
I am using this code to call a custom tag called broadcast.cfm

<cf_broadcast query="fe" orgID = "4">

The query fe is an included file on my site and is available to the page I'm calling the custom tag from.

In the custom tag I am referencing the query like:

<cfloop query="#attributes.query#">

but I keep getting this error:
"The value of the attribute query, which is currently "fe", is invalid. "

I must be missing something really simple here but can't figure out what.
    This topic has been closed for replies.
    Correct answer -__cfSearching__-
    rdk8487 wrote:
    > In the custom tag I am referencing the query like:
    > <cfloop query="#attributes.query#">
    > but I keep getting this error:
    > "The value of the attribute query, which is currently "fe", is invalid. "

    It is a scoping problem. The query is defined in the calling page. To access it by name, within the custom tag, use the "caller" scope.

    <cfloop query="caller.#attributes.nameOfTheQuery#">

    4 replies

    -__cfSearching__-Correct answer
    Inspiring
    December 4, 2008
    rdk8487 wrote:
    > In the custom tag I am referencing the query like:
    > <cfloop query="#attributes.query#">
    > but I keep getting this error:
    > "The value of the attribute query, which is currently "fe", is invalid. "

    It is a scoping problem. The query is defined in the calling page. To access it by name, within the custom tag, use the "caller" scope.

    <cfloop query="caller.#attributes.nameOfTheQuery#">

    Inspiring
    December 4, 2008
    quote:

    Originally posted by: -==cfSearching==-
    rdk8487 wrote:
    > In the custom tag I am referencing the query like:
    > <cfloop query="#attributes.query#">
    > but I keep getting this error:
    > "The value of the attribute query, which is currently "fe", is invalid. "

    It is a scoping problem. The query is defined in the calling page. To access it by name, within the custom tag, use the "caller" scope.

    <cfloop query="caller.#attributes.nameOfTheQuery#">




    If the query object is passed to the custom tag via an attribute you shouldn't need the caller scope. See attached sample.

    Inspiring
    December 4, 2008
    quote:

    Originally posted by: JR "Bob" Dobbs
    If the query object is passed to the custom tag via an attribute you shouldn't need the caller scope. See attached sample.



    Yes, I believe you do because the query object resides in the caller scope. Using query="attributes.query" fails because CF treats it as a literal string.

    Inspiring
    December 4, 2008
    Put these two lines at the start of your custom tag.

    <cfdump var="#attributes#">
    <cfflush>

    Then start passing various things for the query attibute. That will help you troubleshoot.
    rdk8487Author
    Participating Frequently
    December 4, 2008
    Thanks. I tried that and got:

    "Complex object types cannot be converted to simple values."

    Since fe is the name of the query I'm not sure why it should be treated as a variable though.
    Inspiring
    December 4, 2008
    If the pound signs are omitted CF will assume "fe" is a string literal and not a variable. It might help if you could post your code. I was able to use #fe# without seeing an error. I have attached the sample code for the custom tag and calling page.

    Using "fe" as the value of query displays "Value is not a query", using "#fe#" displays the list of column names for the query object. Note for my example the orgID attribute is not used.
    Inspiring
    December 4, 2008
    "fe" is a string.
    rdk8487Author
    Participating Frequently
    December 4, 2008
    can you elaborate? I'm not sure what you're telling me.
    Inspiring
    December 4, 2008
    <cf_broadcast query="fe" orgID = "4"> <!--- here "fe" is string --->

    <cf_broadcast query="#fe#" orgID = "4"> <!--- add pound signs to treat fe as a variable name --->