4 Replies Latest reply on Feb 17, 2007 12:24 AM by BKBK

    Using cf tags in cfscript

    phlebas
      I would like to use cf tags inside cfscript, for example cfquery and cflocation. What is the best way to achieve this.

      Cheers
        • 1. Re: Using cf tags in cfscript
          Level 7
          The short version is: you cannot use tags withing CFScript.

          The slightly longer version is: write UDF replacements for the tags in
          question.

          --
          Adam
          • 2. Using cf tags in cfscript
            BKBK Adobe Community Professional & MVP
            Examples of querying and redirecting by means of cfscript:

            <!--- Script to redirect to testFile.cfm --->
            <cfscript>
            context = getPageContext();
            context.setFlushOutput(false);
            response = context.getResponse();
            response.sendRedirect("testFile.cfm");
            </cfscript>

            For the query script, you will find an idea or two in this Coldfusion TechNote on making a JDBC connection in CFML. In particular, have a look at the download script.






            • 3. Re: Using cf tags in cfscript
              satbeh
              Here is the way to use cfquery within cfscript

              <cfoutput>

              <CFSCRIPT>
              SQLString = "<!---Your Query Here --->";
              DATASOURCE = "<!---Datasource here --->";
              checkUser = CFQUERY(SQLString: SQLString,DATASOURCE: DATASOURCE);
              if (checkUser.recordCount neq 0)
              WriteOutput("Welcome Back, " & checkUser.first_name);
              else
              WriteOutput("Your UserName is Wrong.. try again!");
              </CFSCRIPT>

              <cffunction name="CFQUERY" access="public" returntype="query">
              <cfargument name="SQLString" type="string" required="yes">
              <cfargument name="Datasource" type="string" required="yes">
              <cfargument name="dbType" type="string" default="">
              <cfquery name="RecordSet" datasource="#arguments.Datasource#" dbtype="#arguments.dbType#">
              #preserveSingleQuotes(arguments.SQLString)#
              </cfquery>
              <cfreturn RecordSet>
              </cffunction>

              </cfoutput>

              thanks
              --
              Satyajit Behera
              MindfireSolutions,
              Bhubaneswar
              • 4. Using cf tags in cfscript
                BKBK Adobe Community Professional & MVP
                Here is the way to use cfquery within cfscript
                The challenge is to do a query without the cfquery tag and redirect without the cflocation tag.