Skip to main content
Participant
March 10, 2022
Question

queryFilter

  • March 10, 2022
  • 4 replies
  • 560 views

How to code 'queryFilter'. I followed the instuctions CF user guide to the letter (and all other variations) and I'm still stuck.

    This topic has been closed for replies.

    4 replies

    Alan4aAuthor
    Participant
    March 11, 2022
    This is my code:























    component="FreshStructure_2018/component/boolean"

    method="twoDimension"

    returnvariable="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){

    *return* obj.sumBoolean="#maxBoolean#"

    })




    EddieLotter
    Inspiring
    March 11, 2022

    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.

     

    Alan4aAuthor
    Participant
    March 11, 2022
    This is my code:


    "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){

    *return* obj.sumBoolean="#maxBoolean#"

    })

    EddieLotter
    Inspiring
    March 10, 2022

     @Alan4a, show us your test code and we'll show you where you're going wrong.

    Community Expert
    March 10, 2022

    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:

     

    filteredQuery = QueryFilter(myQuery, function(obj) {
         return obj.amount >30
    })
     
    In the above example, obj is a value that changes to represent each individual row from the query. Each row has a column called "amount", so we're looking at the amount of each row as QueryFilter iterates through the set of rows. If amount is greater than or equal to 30, that row is stored in the new, filtered query. So given a set of amounts that looks like 10, 20, 30, 40, 50 the QueryFilter function will identify the third, fourth and fifth rows and copy them into a new query object called "filteredQuery". The function is called QueryFilter because you always get a subset of your original query.

     

    Dave Watts, Eidolon LLC

    Dave Watts, Eidolon LLC