Customer Portal

Get Involved. Join the Conversation.

Topic

    Shiloh Madsen
    Answers/List and Reports: Filter passingAnswered
    Topic posted September 9, 2013 by Shiloh MadsenBronze Trophy: 5,000+ Points 
    1921 Views, 23 Comments
    Title:
    Answers/List and Reports: Filter passing
    Content:

    Sorry for what amounts to, essentially a fishing expedition, but I simply cannot find good documentation on what seems to be one of the more complicated aspects of CP functionality. I am working on a few widget extensions, one that presents a different form of product selector as a typeahead and I am having a headache of a time getting that to hook into the search answers life cycle. In addition to that, some other functionality I have coded surrounding primary product seems to actually be affecting my searches (primary product always gets filled in on a blank search) and I simply don't know why. 

    So basically what I am trying to understand is what actually happens when i click the search answers button. Where are the product, category and keyword filters being read from and how do I overrride those. Looking at the submit button itself was pretty nearly useless...its code is so minor that I know the heavy lifting is going on elsewhere. It seems that at some point work ends up at getReportData in ajaxRequest.php but there must be one or more stops in between. Would anyone out here have any more insight into what those extra stops are?

    Best Comment

    Patrick Walsh

    Hi Shiloh,

    The ProductCategorySearchFilter widget is probably what is modifying your search.  When you click the search button it is raising an event and all of the search aware widgets can feed in filters.  So the KeywordText widget is adding any keywords, the filters for product and category come from the ProductCategorySearchFilter widget, etc.  The KeywordText widget makes it easier to see what's going on here.  Here are the salient parts of the code from KeywordText:

    1. RightNow.Widgets.KeywordText = RightNow.SearchFilter.extend({

    We extend from the SearchFilter base.

    2. constructor: function() { ... this.searchSource().on("search", this._onGetFiltersRequest, this); ... }

    In the constructor, we register for the search event and call a handler, _onGetFiltersRequest.
     
    3. this._eo.filters.data = this.Y.Lang.trim(this._textElement.get("value"));
            this._searchedOn = this._eo.filters.data;
            return this._eo;
     
    Finally we setup some filters and return them in the _onGetFiltersRequest handler.  
     
    So knowing all of this, you should be able to either extend the product filter widget and modify it to do what you want or to create a widget that extends from RightNow.SearchFilter and to modify the filters when the search event is raised.
     
    Hope that helps!
     
    ..Patrick
     
     

     

    Comment

    • Shiloh Madsen

      Looks like its not coming through on the getReportData call:

       

      1. filters:
        {"recordKeywordSearch":true,"searchType":{"filters":{"rnSearchType":"searchType","fltr_id":5,"data":5,"oper_id":1,"report_id":176},"type":"searchType"},"keyword":{"w_id":"KeywordClass_11","filters":{"searchName":"keyword","data":"","rnSearchType":"keyword","report_id":176}},"p":{"w_id":"ProductTypeahead_13","filters":{"rnSearchType":"menufilter","searchName":"p","report_id":176,"fltr_id":2,"oper_id":10,"data":[[]]}},"c":{"filters":{"fltr_id":3,"oper_id":10,"optlist_id":12,"report_id":176,"rnSearchType":"menufilter","data":[null]},"type":"map_cat_hierarchy","report_default":"~any~"},"page":2,"per_page":0,"report_id":176,"sort_args":{"w_id":"SortBy_14","filters":{"searchName":"sort_args","report_id":176,"data":{"col_id":-1,"sort_direction":1}}}}
    • luke davison

      It looks like your post got truncated. Do you mind re-posting?

    • Shiloh Madsen

      Not truncated...just ran off the screen. I formatted it a bit.

        "recordKeywordSearch":true,
        "searchType":{
          "filters":{
            "rnSearchType":"searchType",
            "fltr_id":5,
            "data":5,
            "oper_id":1,
            "report_id":176
          },
          "type":"searchType"
        },
      "keyword":{
      "w_id":"KeywordClass_11",
      "filters":{
      "searchName":"keyword",
      "data":"",
      "rnSearchType":"keyword",
      "report_id":176
      }
      },
      "p":{
      "w_id":"ProductTypeahead_13",
      "filters":{
      "rnSearchType":"menufilter",
      "searchName":"p",
      "report_id":176,
      "fltr_id":2,
      "oper_id":10,
      "data":[[]]
      }
      },
      "c":{
      "filters":{
      "fltr_id":3,
      "oper_id":10,
      "optlist_id":12,
      "report_id":176,
      "rnSearchType":"menufilter",
      "data":[null]
      },
      "type":"map_cat_hierarchy",
      "report_default":"~any~"
      },
      "page":2,
      "per_page":0,
      "report_id":176,
      "sort_args":{
      "w_id":"SortBy_14",
      "filters":{
      "searchName":"sort_args",
      "report_id":176,"data":{
      "col_id":-1,"sort_direction":1
      }
      }
      }
      }
    • luke davison

      Hey Shiloh,

      It appears that the problem is with the "data" property. For the product filter it's [[]] and for the category filter it's [null]. You might need to use the JavaScript debugger to step through the _getFiltersRequest method you posted to see why it's setting the values like that. I would start by adding breakpoints on lines in that method that set this._eo.filters.data. Hopefully this will point you in the right direction.

      Regards,
      Luke.

    • Shiloh Madsen

      Thanks for making me look a bit more deeply! The problem seems to be from me reading the value in the typeahead field, but as the typeahead clears in page transition, it is no longer there for pagination on the results page. So now I should just have to find a way to repopulate that field with the search term and I'll probably be good to go. 

    • Shiloh Madsen

      Ok, so two steps forward, one step back. So I have further data, and it LOOKED like I fixed the get filters problem..but all new ones. So heres where I stand. I grabbed a headers from both the vanilla search and from my updated search:

      Vanilla

      {"recordKeywordSearch":true,"searchType":{"filters":{"rnSearchType":"searchType","fltr_id":5,"data":5,"oper_id":1,"report_id":176},"type":"searchType"},"keyword":{"w_id":"KeywordText_13","filters":{"searchName":"keyword","data":"","rnSearchType":"keyword","report_id":176}},"p":{"w_id":"ProductCategorySearchFilter_10","filters":{"rnSearchType":"menufilter","searchName":"p","report_id":176,"fltr_id":2,"oper_id":10,"data":[[36,49]]}},"c":{"w_id":"ProductCategorySearchFilter_11","filters":{"rnSearchType":"menufilter","searchName":"c","report_id":176,"fltr_id":3,"oper_id":10,"data":[[]]}},"page":2,"sort_args":{"w_id":"SortList_12","filters":{"searchName":"sort_args","report_id":176,"data":{"col_id":-1,"sort_direction":1}}},"report_id":176,"per_page":0}
       
      Custom
      {"recordKeywordSearch":true,"searchType":{"filters":{"rnSearchType":"searchType","fltr_id":5,"data":5,"oper_id":1,"report_id":176},"type":"searchType"},"keyword":{"w_id":"KeywordClass_11","filters":{"searchName":"keyword","data":"","rnSearchType":"keyword","report_id":176}},"p":{"w_id":"ProductTypeahead_13","filters":{"rnSearchType":"menufilter","searchName":"p","report_id":176,"fltr_id":2,"oper_id":10,"data":[[36,47]]}},"c":{"filters":{"fltr_id":3,"oper_id":10,"optlist_id":12,"report_id":176,"rnSearchType":"menufilter","data":[null]},"type":"map_cat_hierarchy","report_default":"~any~"},"page":1,"per_page":10,"sort_args":{"w_id":"SortBy_14","filters":{"searchName":"sort_args","report_id":176,"data":{"col_id":-1,"sort_direction":1}}},"search":1}
       
      Looks like the product is generated just fine, however, when I do a follow up search it hangs with a new error in console: 
      "Cannot read propterty 'linkID' of undefined". I checked the header for this one and its identical, with just a different product. 
       
      Just for grins, I tried to hard code the product ids and I never see this error...but that could just be because my search terms aren't changing. 
       
      Starting to feel like every bug I squash releases a new one to track down. Any direction for THIS trouble?
    • Shiloh Madsen

      So I found a very hackish workaround but now I have this 'interesting' intermittent glitch. Sometimes when I search on a new product, the url changes from /app/answers/list to /euf/assets/themes/themename...and im not entirely certain why this substitution is happening. Any illumination on this would be fantastic. 

      For those interested in my "hack" to solve the linkid of undefined...this was clearly a js issue with the searchfilters class not getting the right data for the onReportResponse method...however, the URL did get the memo that my product id had changed. As a result, I just tossed in my own code on the widget onReportResponse function to do a location.reload();. This caused the page to refresh after the report came in, thus providing me with useful report data. Ajax response isn't working, but the page itself is. 

    • Jeremy Watson

      Shiloh,

      Is it possible that JavaScript has not finished loading before you try a new search?  When I've seen something similar to what you describe, it is often because I am performing an action before all of the framework and widget JS has loaded and executed.

      James