Highlighted

function calls in cfscript

New Here ,
Oct 07, 2014

Copy link to clipboard

Copied

i am looking for an example of using cfscript to pass varibles into a query  and NOT HARDCODED into the addParam value attribute.

Sugesstions ?

Views

150

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

function calls in cfscript

New Here ,
Oct 07, 2014

Copy link to clipboard

Copied

i am looking for an example of using cfscript to pass varibles into a query  and NOT HARDCODED into the addParam value attribute.

Sugesstions ?

Views

151

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 07, 2014 0
BKBK LATEST
Adobe Community Professional ,
Oct 08, 2014

Copy link to clipboard

Copied

You could just create your own custom function. To illustrate, take the following example from the documentation:

<cfscript>

    queryService = new query();

    queryService.setDatasource("cfdocexamples");

    queryService.setName("getParks");

    queryService.addParam(name="state",value="MD",cfsqltype="cf_sql_varchar");

    queryService.addParam(value="National Capital Region",cfsqltype="cf_sql_varchar");

    result = queryService.execute(sql="SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE = :state and REGION = ? ORDER BY ParkName, State ");

    getParks = result.getResult();

</cfscript>

<cfdump var="#getParks#">

You could customize it as follows:

<cfscript>

    queryService = new query();

    queryService.setDatasource("cfdocexamples");

    queryService.setName("getParks");

    qParams = getQueryParams();

    result = queryService.execute(sql="SELECT PARKNAME, REGION, STATE FROM Parks WHERE STATE LIKE '#qParams.stateFirstLetter#%' and REGION LIKE '#qParams.regionFirstLetter#%' ORDER BY State, ParkName");

    getParks = result.getResult();

    function getQueryParams() {

        var myParams=structnew();

        myParams.stateFirstLetter = "M";

        myParams.regionFirstLetter = "N";

        return myParams;

    }

</cfscript>

<cfdump var="#getParks#">

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 08, 2014 0