5 Replies Latest reply on Jul 6, 2007 3:29 PM by Newsgroup_User

    Function  call

    mama_karlo
      I need to call a function and pass a query to it by clicking a button (or link).
      What is the best way to do it?

      The function actually converts the passed query into excel format and displays it.


      Any suggestions welcome
        • 1. Re: Function  call
          Dan Bracuk Level 5
          Do it the same way you call any other function. The fact that your argument will be a query shouldn't be an issue, just make sure you declare it as such in your cfargument tag.
          • 2. Re: Function  call
            mama_karlo Level 1
            How do I do it by clicking a button? The query is only available on the same page as the button.

            Thnx
            • 3. Re: Function  call
              Level 7
              The query is only available on the same page as the button.

              No it's not. By the time a button has been displayed the CF engine has
              forgotten about the query unless you did something to preserve it in a
              persistent scope.

              You need to keep the difference between the server and client seperate
              here and understand what happens from request to request and that by
              default the web is a stateless environment.

              The simplest way to do what you are wanting is to have the button make
              the same request the built the original page with a simple URL parameter
              that means "return CSV" and then the ColdFusion template called for the
              request will build the desired file and return it as the response the
              this new request.
              • 4. Re: Function  call
                mama_karlo Level 1
                Well, thank you for the lesson on the web stateless environment.
                My whole point was to at least pass the query that IS available to the calling page...


                • 5. Re: Function  call
                  Level 7
                  My whole point was to at least pass the query that IS available to the
                  calling page...

                  But that statement does not work in a stateless environment. The query
                  is NOT available to be passed.

                  1) A request was made to web server.

                  2) Web server determines request is for ColdFusion, passes request to CF.

                  3) CF Process request creating and using query and builds response.

                  4) Response is returned to web server, CF clears all data for garbage
                  collection and goes on to next request.

                  5) web server passes response to client.

                  6) client renders response and waits for user interaction.

                  7) user activates button, new request is sent to web server.

                  8) It all starts over again.

                  There is no "query" anymore by the time a user sees a button and can
                  click on it, unless something is done to save it in a persistent scope
                  so that it can be used from request to request. And even then, a new
                  request must be made to do something with the query.