Skip to main content
Inspiring
April 20, 2008
Answered

Dynamic named arguments

  • April 20, 2008
  • 3 replies
  • 303 views
Hi,

I have 2 cfc methods one receives 3 arguments, id,fieldid,fieldvalue. Where fieldid is a db column name and fieldvalue is the value of that field. I want to pass this info to another method which accepts many more optional arguments. I would like to use the arguments.field as the name of an argument for the 2nd method

e.g. my2ndmethod(arguments.fieldid=arguments.fieldvalue)

However, this doesn't seem to be working. Is there anyway to do this other than using a switch case on arguments.fieldid and then hardcoding each possible fieldid in each cfcase?

Any ideas/suggestions/workarounds?

Many thanks,

Dave
This topic has been closed for replies.
Correct answer Dave Phipps
Problem solved. I used cfinvoke to invoke the second method and then used cfinvokeargument name="#arguments.fieldid#" value="#arguments.fieldvalue#" and it works a treat!!

Cheers,

Dave

3 replies

Dave PhippsAuthorCorrect answer
Inspiring
April 22, 2008
Problem solved. I used cfinvoke to invoke the second method and then used cfinvokeargument name="#arguments.fieldid#" value="#arguments.fieldvalue#" and it works a treat!!

Cheers,

Dave
Inspiring
April 20, 2008
But wouldn't argumentcollection pass arguments.fieldid and arguments.field value to the 2nd method? My second method would not know what fieldid was.

arguments.fieldid could be anything for that particular data table e.g. firstname or lastname. arguments.fieldvalue holds the corresponding value of that field e.g. Dave or Phipps.

My 2nd method has arguments for firstname, lastname so argumentCollection would not fit in this situation.

Although could I use cfinvokeargument?? I'll try it in the morning! (00:22 here).

I think I have had a lightbulb moment.

Thanks Dan, you might have pointed me in the right direction!

Cheers,

Dave
Inspiring
April 20, 2008
if I understand the question correctly,
argumentcollection=arguments
is one of my favourite attributes when using cfinvoke