This content has been marked as final. Show 5 replies
Is it possible to return multiple variables from a <cffunction> using
<cfinvoke>. I understand I can use a struct, but I am looking for a way
to return multiple stand-alone variables.
You can not return multiple values from a function without using a
structure to combine them. You can have the function set variables
outside the function in the calling scope or higher, but most developers
would consider this to be very poor design.
Something against structures? They are very handy things.
I am new to creating web services, and noticed that the samples I have looked at have multiple output variables, which makes grabbing the right piece of data a snap. I was interested in trying to create this kind of thing with a .cfc. No problem using a struct, but the app I am using to consume the web service doesn't give me much flexibility in parsing the struct. Thanks for you insights.
> I am new to creating web services, and noticed that the samples I have looked
> at have multiple output variables,
Can you post an example of that?
OK, I modified my web service get7.cfc?wsdl to return a structure with 3 elements representing the 3 columns in my table. You can view a <cfdump> of the service at get7.cfm
The code for my cfc is attached.
The web service works fine, but fails when I try to consume it with my dashboard. I am creating a dashboard with Crystal Xcelsius, so I realize it is basically an Xcelsius issue, but any tips would be appreciated. I have successfully created and consumed (with Xcelcius) web services that return a single string variable, but can't get it to work with 2 dimensional (repeating) elements (ie query data). Please take a look at my cfc code and see what you think.
Add a function to your cfc that produces a simple 2D array. If you are able to consume that with Xcelsius, then create an array instead of a function with your real function. If not, try xml.
As an aside, it's a good idea to use the var keyword in your function to create every variable, including the query. This keeps the variable names local to the function and prevents mysterious problems in the programs that use them.