froadie
froadie

Reputation: 83153

Can I pass a struct to a function and have it translated to multiple parameters?

In ColdFusion, is there any way to pass in a struct of parameters to a function with multiple optional parameters?

For example, I want to do something like this:

<cfset myResults = myFunction(myStruct) />

<cffunction name="myFunction" ... >
   <cfargument name="myArg1" type="numeric" required="no" default="" />
   <cfargument name="myArg2" type="string" required="no" default="" />
   <cfargument name="myArg3" type="numeric" required="no" default="" />
.....
</cffunction>

Where "myStruct" has a random combination of key-value pairs - for example, "myArg3":222 and "myArg2":"hello".

Is this possible, or do I have to specifically list each argument (with a check of "isDefined" for each one)?

Upvotes: 1

Views: 1589

Answers (1)

froadie
froadie

Reputation: 83153

Ok, I haven't tested this yet, but I just realized I might be able to do this using a <cfinvoke argumentCollection="#myStruct#">. Will try that now...

Edit: This did work! And Sergii's suggestion for my original syntax without a cfinvoke works as well.

Upvotes: 3

Related Questions