3 Replies Latest reply on Apr 22, 2008 1:29 AM by Dave Phipps

    Dynamic named arguments

    Dave Phipps Level 1

      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,

        • 1. Re: Dynamic named arguments
          Dan Bracuk Level 5
          if I understand the question correctly,
          is one of my favourite attributes when using cfinvoke
          • 2. Re: Dynamic named arguments
            Dave Phipps Level 1
            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!


            • 3. Re: Dynamic named arguments
              Dave Phipps Level 1
              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!!