Customer Portal

Get Involved. Join the Conversation.

Topic

    Patricia Harvath
    Passing 'p' with the ProductCategoryInput widget.Answered
    Topic posted December 28, 2011 by Patricia HarvathBronze Medal: 1,250+ Points, last edited January 17, 2012 
    1772 Views, 27 Comments
    Title:
    Passing 'p' with the ProductCategoryInput widget.
    Content:

    Hi,

    I am trying something that should be easy.  On the home page, we would like users to select a product and on submission, be redirected to the ask page with the product pre-selected.

    So, I am trying to pass the selected product from the ProductCategoryInput widget from the home page to the ask page using add_params_to_url in the FormSubmit widget. When I hit the submit button, I am redirected to the ask page, but the 'p' param is not added to the URL. What am I missing?

    We're using Nov '10.

    Thanks.

    Code Snippet:

    Best Comment

    Ernie Turner

    Ok, you should be able to do this using the ProductCategorySearchFilter widget. I'm not entirely sure if all of these attributes are available on your version or not, but adding this should work

        <rn:widget path="search/ProductCategorySearchFilter" search_on_select="true" report_page_url="/app/ask" show_confirm_button_in_dialog="true"/>

    This will display the dropdown and nothing else, and when the user selects an item, it will redirect to the ask page with the product parameter in the URL which should pre-populate the widget on the ask form.

    Comment

    • Ernie Turner

      Ok, you might need to do some debugging in the _takeUserToAskPage function. The data format might be different than what I was expecting. That data you need should be somewhere in the data parameter though.

    • Patricia Harvath

      What exactly am I looking for?

    • Ernie Turner

      An array of product ID's. I'm not quite sure why the code I have isn't working for you, but there should be something in there that you can join() together to give you the 1,10,50 format that you're trying to generate.

    • Patricia Harvath

      I am sorry, but you've completely lost me. 

    • Ernie Turner

      Within the custom widget code I sent you, using something like Firebug, put a breakpoint on the first line of the '_takeUserToAskPage' function. While there, inspect the 'data' variable to see what it contains. Somewhere in there should be an array of product ID"s for the value that you just selected. You'll want to take that array and call join() on it (like the code I posted does), and then append that string to the end of the AAQ page URL.

    • Patricia Harvath

      Thanks for the explanation.   I think this is what you are describing, but I am not sure how to grab the array and call join() on it.  Am I close?

       

      js
      Object { linkingOn=0, hierData=[1], hm_type=14}

      hierData
      [[Object { value=0, label="No Value"}, Object { value=6031, label="Network Testing", parentID=0, more...}, Object { value=4166, label="Planning A Rental ", parentID=0, more...}, 5 more...]]

      0
      [Object { value=0, label="No Value"}, Object { value=6031, label="Network Testing", parentID=0, more...}, Object { value=4166, label="Planning A Rental ", parentID=0, more...}, 5 more...]

      0
      Object { value=0, label="No Value"}

      label
      "No Value"

      value
      0

      1
      Object { value=6031, label="Network Testing", parentID=0, more...}

      hasChildren
      0

      label
      "Network Testing"

      parentID
      0

      selected
      false

      value
      6031

    • Ernie Turner

      And what value did you select from the dropdown when you got that data?

    • Patricia Harvath

      I can see the values of the items in the dropdown (I selected value 6031 with a label of 'Network Testing'.  But I don't know how to call that array dynamically.  I am not sure what name to put with it.

      When I click on the dropdown menu and select something, I have to step through the function and nothing ever shows up as actually being selected, 'selected' never equals 'true'.

       

    • Ernie Turner

      Ok, so after investigating this a bit further, it looks like the code I provided won't quite work on the version that you're on. We didn't add the hierChain property until a later release apparently. However, you should be able to accomplish the same thing if we switch over to the ProductCategorySearchFilter widget. So, in your custom widget view, change the widget call to this:

          <rn:widget path="search/ProductCategorySearchFilter" show_confirm_button_in_dialog="true"/>

      And then change your logic file to have this:

      RightNow.Widget.SampleWidget = function(data, instanceID)
      {
          this.data = data;
          this.instanceID = instanceID;

          RightNow.Event.subscribe('evt_productCategoryFilterSelected', this._takeUserToAskPage, this);

      };
      RightNow.Widget.SampleWidget.prototype = {
          _takeUserToAskPage: function(type, data)
          {
              var productChain = data[0].filters.data[0].join(',');
              RightNow.Url.navigate('/app/ask/p/' + productChain);
              return false;
          }
      };

      Sorry for all the hassle in getting this to work. :(

    • Patricia Harvath

      No apologies necessary.  I appreciate the help.  I've tried this new approach, but I am still getting the error alert before the switch over to the ask page. 

      Frown

      How difficult would it be to disable the alert for this widget?  Is that something burried in the RN code?

      Another thought I had was to use Connect PHP and do a ROQL call against the database to get the dropdown items and then pass the param in the URL.  Does this seem like it would work?

      Thanks again for your efforts!

    • Ernie Turner

      Hmm, that's odd. I tried this on a site that is the same version as what you're using. Do you have an example where I can try this out at all?

      Yes, you could probably poke around with using ConnectPHP to do this, but that would require customizing either the of the product/category treeview widgets which, while possible, is really less than ideal. Since I was able to get this working on a Nov 2010 site, it seems like we should be able to do the same on yours.

    • Patricia Harvath

      Ernie was nice enough to log onto my development site and work through the issue. His answer worked great for me. Here's his message to me regarding the fix:

      Ok, so this has definitely been fixed in the February 2011 release, but in the meantime, I think we can fix this by overwriting the default failure handler to not display the error dialog if the request fails. Within the /euf/development/javascript/autoload.js file, add this chunk of code

      RightNow.Event.subscribe("on_before_ajax_request", function(name, data){
      data = data[0];
      if(data.url === '/ci/ajaxRequestMin/getHierValues'){
      data.failureHandler = function(response){};
      }
      });

      This is basically subscribing to an event the framework throws prior to making an ajax request. We're checking if the request that's being made is to a specific URL (in this case, we're checking if it's the request we want to modify), and then setting the failure handler function to not do anything. I haven't been able to test this on an actual site, but it should work, let me know if you have problems and I can poke at what you've done.

      Also, it'd be worth adding some comments to that code to say why it's there and that it can be removed once the site has been upgraded. There's no risk of it causing an upgrade problem, but it is just unnecessary once you've upgraded.