Archive
Highlighted

Activate a module from within another module using javascript

Explorer

I have a series of "homemade" text input modules. Each module has a submit button, that can separately execute a search, or if arranged so, can execute a search with context that was passed by way of an xml cascade. This solution has one very big problem:

-Since the search context propagates downward in the cascaded xml tree, we ignore text input from relative ancestors.

Ideally we could fire the parent TimeRangePicker when a user submits a text input search.

I've tried using getRootAncestor(), getModulesInTree(), and getAncestors(), but I'm not having much luck.

I guess a more general question might be, what is a possible pattern for selecting and initializing a module from within the javascript of a separate module?

Thanks,
Wade

Highlighted

Re: Activate a module from within another module using javascript

SplunkTrust
SplunkTrust

If your intention in making homemade text input modules is to get something easier to use than ExtendedFieldSearch, have you considered using Sideview Utils? You can get the latest (2.3) from http://sideviewapps.com/apps/sideview-utils and it's free for internal use, and it has a TextField module that's vastly easier to use than ExtendedFieldSearch.

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

Explorer

Hi SideView, SV modules are the best!
I liken them to driving a Ferrari in place of my current set of wheels. But I was hoping one last pint of oil could keep our jalopy running before we full cross over to SideView Utils.
I was hoping there's a way to activate the TRP module.. maybe using Jquery, and pass the currently/already selected TRP params to the child text inputs (Tis).. or possibly inserting a faux dispatch module as a parent to the Tis, allowing us to push search context from TRP parent to the TI children..In either case, I'm still not sure how to "activate" a parent module.
Thanks!

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

SplunkTrust
SplunkTrust

Well, my feeling is that you're living a little too far outside the assumptions of the hierarchy and activating the TRP in some proper way at the right time wont be enough. You could stitch in a NullModule into the view, implement getModifiedContext on that NullModule, and have that getModifiedContext implementation put in all the various hoo-hah from your homemade text inputs. that way you'd be working from inside the system, and not fighting the hierarchy and its event-driven cascadey nature. Feel free to post pastebin for code and xml and I can comment in greater detail.

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

Explorer

Ok I've just set up a pastebin acct, and posted the xml and javascript. Oh and full disclosure, the "homemade" text input module (named TextInputterModule) was taken from the web intelligence funnel application. It makes an attractive array of panel separated text inputs. The xml is here: http://pastebin.com/3hiAFYMp and the accompanying javascript: http://pastebin.com/4agUSJeQ
So it sounds like a better solution is to merge text input modules, into a single null module that renders multiple text inputs? Right now we have a separate panel per input, which works well for the user requirements.

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

SplunkTrust
SplunkTrust

Well, the module seems "ok", although of course you've hacked it a fair bit away from its original purpose inside the Web Intelligence app, and it may never have received any particularly wide QA pass outside of that one app.

I think the problem may just be one of the following two things:

1) you have an autoRun="True" on the HiddenSavedSearch when it should be one level up on the TimeRangePicker.

2) if that savedsearch has it's own timerange, then it'll be clobbering the timerange contributed by the TimeRangePicker. It's possible that it would be triggering a big red error message saying that the view was thus misconfigured, but it's also possible that you don't have any Message modules in the view - there are none in the posted snippet. You wouldn't be the first to chase your tail for a long time because there was no Message module to display the root cause.

By some coincidence, I'm on the verge of posting a new version of Sideview Utils, that has two new features in it. One is that the TextField module can be configured as a multiline textarea. And another is a new module called ArrayValueSetter. If you're familiar with how multiselect Pulldown modules work, ArrayValueSetter is sort of like the template+separator+outerTemplate logic of Pulldown, but without the Pulldown. Anyway, combine that with ValueSetter's existing delim param, and you could just have a simple control where users enter each searchterm on a different line, and the modules turn this automatically itno ( foo="line1" OR foo="line2" OR foo="line3" ) under the hood, or if you like | where foo="line1" foo="line2", and so on and so forth.

View solution in original post

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

SplunkTrust
SplunkTrust

Note that Sideview Utils 2.4 launched, and with that version the TextField module gained the ability to work in a multiline mode, and together with the new ArrayValueSetter module it can implement the use case that I described above. A very similar question and answer was posted recently and I have a lot more details and sample config posted there -- http://splunk-base.splunk.com/answers/74700/form-with-a-multi-line-text-box-that-will-or-every-line-...

0 Karma
Highlighted

Re: Activate a module from within another module using javascript

Explorer

I'm very new to web development, but I ended up with two really big questions from this effort:

1) Is it possible to call methods of an instantiated module, from within a different module, and execute that instantiated module's methods using jquery?

2) Is there a way to do this using the splunk module API?

I'm really not sure how to do "1". How do we find the module object?

I was able to call the splunk root module (the TRP) and then push context downstream. This was after passing the MultiLineInputters (MLI) context upstream to ensure the context remains intact from each MLI. I believe we potentially bypass the clobber factor, by exporting the context to the root, using "passContextToParent". In terms of UI impact, this allows users to submit their modified search from any MLI of their choosing. Leaving in that UI feature, helps prevent users from navigating a swath of web page collateral to reignite a search from the TRP.

I guess a proper modular addition or change should be a single boolean param to indicate if it's the first module. That will provide the condition to append "| where" in the search.

I've attached the code mod within TextInputterModule.

pushSearch: function() {
    this.prepareContext();
    this.passContextToParent(this.prepareContext());
    var root = this.getRootAncestor();
    root.pushContextToChildren();
},

There are several other great modular traversal methods, I refer those interested to this link: http://dev.splunk.com/view/SP-CAAADW2

I love the concept of your new sideview feature. Especially given the MLI multi module solution uses substantial UI real estate.

In the new side view modules it would be great if the combination of the new TextField and ArrayValueSetter modules could provide multiple types of search terms such that | where foo1="line1" OR foo2="line2" OR foobar="line3", that essentially would entirely solve this "hack" workaround.

Thank you for being generous enough to help explain these topics. It's a tremendous contribution!

I placed this comment as an answer due to the size limitations. For some reason I keep getting the spinner when I try to post this answer as "comment". Maybe it's due to that limit? Not sure.
Cheers,
Wade

0 Karma
Speak Up for Splunk Careers!

We want to better understand the impact Splunk experience and expertise has has on individuals' careers, and help highlight the growing demand for Splunk skills.