3 Replies Latest reply on Jul 3, 2006 4:31 AM by |mantra|

    using argumentCollection

    |mantra| Level 1
      can anyone help me with why this won't work please .. i have a form which is put into a structure on processing:

      <cfset projectDetails = structNew()>
      <cfset projectDetails.projectName = "#form.projectName#">
      <cfset projectDetails.description = "#form.description#">

      then am trying to invoke a component and pass the struct to the component .. this is how i'm invoking it:

      <cfinvoke component="modProjects"
      method="uploadProject"
      argumentcollection="#projectDetails#"
      returnvariable="uProject">

      and this is the actual component :

      <cfcomponent output="false">
      <cffunction name="uploadProject" access="public" type="struct" hint="upload new project for recent projects section">
      <cfargument name="projectDetails" required="yes">
      <cfquery name="uProject" datasource="sauce_remoting">
      INSERT INTO projects
      VALUES ('#arguments.projectName#', '#arguments.description#')
      </cfquery>
      </cffunction>
      </cfcomponent>

      Thx in advance
        • 1. Re: using argumentCollection
          Level 7
          The docs probably best explain where you're going wrong.

          http://livedocs.macromedia.com/coldfusion/7/htmldocs/00001051.htm

          The argument collection does not reflect *one* argument, so not
          corresponding directly to one <cfargument> tag; it reflects a structure of
          a set of arguments, so one <cfargument> tag per key of the structure you
          pass.

          --
          Adam
          • 2. Re: using argumentCollection
            BKBK Adobe Community Professional & MVP
            Two things. First, though you explicitly pass the structure using argumentcollection="#projectDetails#" , its keys implicitly become available in the function as the Arguments-scoped variables, arguments.projectName and arguments.description. Hence, the line <cfargument name="projectDetails" required="yes"> is superfluous.

            Second, you mistakenly give cffunction a type attribute, instead of returntype. For example, test

            <cfinvoke component="modProjects"
            method="uploadProject"
            argumentcollection="#projectDetails#"
            returnvariable="uProject">

            <cfdump var="#uproject#">


            with the cfc

            <cfcomponent output="false">
            <cffunction name="uploadProject" access="public" returntype="struct">
            <cfquery name="uProject" datasource="sauce_remoting">
            INSERT INTO projects
            VALUES ('#arguments.projectName#', '#arguments.description#')
            </cfquery>
            <cfscript>
            inserted.status="inserted OK";
            inserted.one=arguments.projectName;
            inserted.two=arguments.description;
            </cfscript>
            <cfreturn inserted>
            </cffunction>
            </cfcomponent>


            • 3. Re: using argumentCollection
              |mantra| Level 1
              hi .. thanks heaps for that, and the quick reply too ... makes sense to me now