All Apps and Add-ons

Sideview Utils: How to automatically redirect to a new page after a simple search is run without any triggers like a button click?

sanfar
Explorer

Hi

I have a page which runs a simple search. After the search, I want to redirect to another page automatically without the use of any triggers like button. For me, the search is working, but the redirector doesn't seem to be responding.alt text

I have set Auto run as true on URLLoader
and just have URL and arg params set on the redirector

<module name="URLLoader" layoutPanel="viewHeader" autoRun="True">

    <module name="Search">
      <param name="search"><![CDATA[
| rest /services/authentication/current-context | search NOT username=splunk-system-user
| eval Page_Action="[Interface]:[Page_Redirector] 
]]></param>

      <module name="HTML">
        <param name="html"><![CDATA[
Search: $search$
]]></param>
      </module>

      <module name="ResultsValueSetter">
        <param name="fields">URL_parameter</param>

        <module name="Gate">
          <param name="requiredKeys">URL_parameter</param>

          <module name="Redirector">
            <param name="arg.parameter">$URL_parameter$</param>
            <param name="url">SCREEN_TO_REDIRECT</param>
          </module>

          <module name="Table" />
0 Karma

sideview
SplunkTrust
SplunkTrust

Hmm.. What's preventing this from working is actually a safeguard built into URLLoader, Redirector and technically the whole module framework.

As you know Redirector is designed to redirect the user as soon as it receives a push of fresh data from upstream. However, when autorun initiates the first push on the page, that push is treated differently and Redirector knows to never redirect on those pushes. Autorun pushes for various reasons have to be able to push all the way down through the hierarchy, even past places where "normal" pushes would stop, like at interactive tables and charts and buttons. So this means autoRun pushes very often find themselves touching Redirector modules, where actually redirecting would be a most inconvenient thing. 😃

This is incidentally why you can be pretty liberal in where you put Redirectors, yet never run into a bug where the page loads only to instantly redirect you away.

You could define a customBehavior in your app though to explicitly override this safeguard, and then use that customBehavior for this redirector.

In application.js, add the following:

if (typeof(Sideview)!="undefined") {

    Sideview.utils.declareCustomBehavior("triggerHappyRedirector", function(redirectorModule) {
        var baseMethodReference = redirectorModule.onContextChange.bind(redirectorModule);
        redirectorModule.onContextChange = function() {
            this.markPageLoadComplete();
            return baseMethodReference();
        }
    });
}

And then add this param to your Redirector module(s)

<param name="customBehavior">triggerHappyRedirector</param>

It's a pretty simple concept. We have our Redirector actually jump the gone and declare the page load complete the moment it receives it's first set of data, and this will take the safety off, so to speak.
Let me know if it works for you. Apologies if the code has typos that I've missed.

0 Karma

sanfar
Explorer

Thanks for your answer.I have changed the functionality of the application to go around this issue,however I will try the solution.It also helped me understand how I can use custom behavior in the app..

Thanks again!

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...