Skip to main content
Participant
July 3, 2006
Answered

using argumentCollection

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
This topic is closed to new replies. Start a new post to keep the conversation going.
_mantra_Correct answer
Participant
July 3, 2006
hi .. thanks heaps for that, and the quick reply too ... makes sense to me now

3 replies

Inspiring
July 3, 2006
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
Translate
BKBK
Community Expert
Community Expert
July 3, 2006
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>


Translate
_mantra_AuthorCorrect answer
Participant
July 3, 2006
hi .. thanks heaps for that, and the quick reply too ... makes sense to me now
Translate