Copy link to clipboard
Copied
How to code 'queryFilter'. I followed the instuctions CF user guide to the letter (and all other variations) and I'm still stuck.
Copy link to clipboard
Copied
Did you look at the examples? Did you try running the first one in CFFiddle? This is kind of a complicated function for me to explain, so it might be better just to see a small example working in CFFiddle.
That said, the way this function works is a lot like JavaScript functions work nowadays. The second argument of the function often points to another unnamed function, like this:
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
@Alan4a, show us your test code and we'll show you where you're going wrong.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
What are the asterisks around "function" and "return"?
Your code is being mangled by the forum. Click on the "</>" button at the top of the reply text box, select "Java" as the language even though it is CF, and you will be able to include properly formatted code.
Copy link to clipboard
Copied
Here is an example that combines your code with the example in the QueryFilter documentation:
<cfscript>
sumBoolean=arrayNew(1);
sumBoolean[1]=1;
sumBoolean[2]=2;
sumBoolean[3]=3;
sumBoolean[4]=5;
sumBoolean[5]=8;
sumBoolean[6]=13;
sumBoolean[7]=21;
sumBoolean[8]=34;
cutOffBoolean=10;
qTwoDimension = queryNew("firstName,lastName,userName,sumBoolean","Varchar,Varchar,Varchar,Integer",
[
{firstName="Bruce", lastName="Murray", userName="brucemurray", sumBoolean =
"#sumBoolean[1]#"},
{firstName="Micheal", lastName="Morecroft", userName="michealmorecroft",
sumBoolean = "#sumBoolean[2]#"},
{firstName="Dick", lastName="Weston", userName="dickweston", sumBoolean =
"#sumBoolean[3]#"},
{firstName="Fred", lastName="Sinner", userName="fredsinner", sumBoolean =
"#sumBoolean[4]#"},
{firstName="Don", lastName="Highland", userName="donhighland",sumBoolean =
"#sumBoolean[5]#"},
{firstName="Don", lastName="Highland", userName="donhighland",sumBoolean =
"#sumBoolean[6]#"},
{firstName="Peter",lastName="Began", userName="peterbegan",sumBoolean =
"#sumBoolean[7]#"},
{firstName="Henry",lastName="Dunes", userName="henrydunes",sumBoolean =
"#sumBoolean[8]#"}
]);
qCandidate=QueryFilter(qTwoDimension,function(obj){
// pick out rows whose sumBoolean is less than the cut-off value
return obj.sumBoolean < cutOffBoolean;
})
writeOutput("The filtered query (qCandidate) is:")
writeDump(qCandidate)
</cfscript>
Copy link to clipboard
Copied
@Alan4a , any joy with that code example?