Skip to main content
Inspiring
February 22, 2012
Answered

Implicit arguments in a CFINVOKE

  • February 22, 2012
  • 2 replies
  • 2311 views

Is it possible, without having to create the variable first and merely use the variable name, to pass an implicity structure in the CFINVOKE's ARGUMENTCOLLECTION attribute?

It would be so much easier if I could do this (I'm using ColdFusion 9 btw).  Or maybe I can create a UDF that I pass that string and it returns a structure based on it as the value for the argumentcollection attribute. Like:

<cfinvoke component="coms.data" method="executeQuery" argumentcollection="{this='that',that='this'}" returnvariable="result">

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Sorry about that Adam.

    Here's my different implementations and resulting errors:

    TRY #1

    <cfinvoke component="#application.coms.data#" method="executeQuery" argumentcollection="#{ file='get-page-data',vars={module='apps',page='home'}}#" returnvariable="local.pageData">

    Error: ColdFusion was looking at the following text:<p>#</p><p>The CFML compiler was processing:<ul><li>The tag attribute argumentcollection, on line 117, column 41.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.</ul>

    TRY #2

    <cfinvoke component="#application.coms.data#" method="executeQuery" argumentcollection=#{ file='get-page-data',vars={module='apps',page='home'}}# returnvariable="local.pageData">

    Error: ColdFusion was looking at the following text:<p>#</p><p>The CFML compiler was processing:<ul><li>The tag attribute argumentcollection, on line 117, column 41.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.<li>A cfinvoke tag beginning on line 114, column 34.</ul>

    TRY #3

    <cfinvoke component="#application.coms.data#" method="executeQuery" argumentcollection="{ file='get-page-data',vars={module='apps',page='home'}}" returnvariable="local.pageData">

    Error: java.lang.String cannot be cast to java.util.Map

    I've also tried putting the structure on separate lines and indents (for readability) based on the braces { }, cause I thought that wouldn't hurt anything.  But for the aforementioned, I put the code all on 1 line.


    TRY #1 works fine for me. And that is the syntax I woudl expect to work.  That said, the secondone works for me too.  I would not expect the third to work, for reasons already stated.

    What exact vesion of CF9 are you on?  I'm on 9.0.1 (9,0,1,274733 to be precise).

    --

    Adam

    2 replies

    Inspiring
    February 22, 2012

    I think that approach would work better without the argumentcollection attribute.  I've not tried it myself though.

    Inspiring
    February 22, 2012

    I suspect, just like any CF expression within a string, you need to put pound-signs around it so CF knows it's not simply a string value.

    --

    Adam

    Inspiring
    February 22, 2012

    @Adamn Cameron

    When I place # signs around the {} and pass the structure implicitly in the argumentscollection attribute, I get a general parsing error about there being # signs in the wrong place.

    @Dan Bracuk

    Without it?  Though I've used argument names as attributes, the problem here is that the structure I was originally passing in has another structure in it, so even if I did:

    <cfinvoke component="coms.data" method="executeQuery" file="get-page-data" dynamicvars="{module='apps',page='home'}" returnvariable="result">

    It still has an issue with the implicitly set structure in the dynamicvars attribute.  Originally, the structure looks like this:

    {file='get-page-data',dynamicvars={module='apps',page='home'}}

    Inspiring
    February 22, 2012

    When I place # signs around the {} and pass the structure implicitly in the argumentscollection attribute, I get a general parsing error about there being # signs in the wrong place.

    Strange.  That ought to work.  Well: it does work.  I can't make much more comment than that, as you have not posted your updated code, nor the exact error msg (both of which you should always do if the question relates to na error you are getting with code).

    --

    Adam