Dashboards & Visualizations

Why am I getting “Uncaught TypeError: Cannot read property 'startSearch' of undefined” when I use mvc.components.get()?

tommywang
Explorer

xml code:

< search id= 'pie_search'>

        < query>index=mtest1 | stats sum(num) by fruit</query>

< /search>

js code:

var mySearch = mvc.Components.get('pie_search');
mySearch.startSearch();

Error:

Uncaught TypeError: Cannot read property 'startSearch' of undefined

Can anyone please tell me what I am missing?

0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

Not sure you get your search correctly, where is that code from? Try

var mySearch = splunkjs.mvc.Components.getInstance("pie_search")

View solution in original post

jeffland
SplunkTrust
SplunkTrust

Not sure you get your search correctly, where is that code from? Try

var mySearch = splunkjs.mvc.Components.getInstance("pie_search")

tommywang
Explorer

It doesn't work for me. The error is the same.
However, I can use both "var mySearch = splunkjs.mvc.Components.getInstance("search1") " and "var mySearch = mvc.Components.get('search1');" to get the object of searchManager in my js file.
The problem is that I can't get the object according to the "id" of search label, like "var mySearch = mvc.Components.get('pie_search')". No matter how I change the "id" of search label, the only way to acquire the object is by the "id" search1.

0 Karma

jeffland
SplunkTrust
SplunkTrust

When you open the dashboard in your browser and check the html code, can you see your searches in the script part after the layout part? They should be after the part about tokens, and there you can confirm what id they have. It looks like somehow, your id isn't set correctly, but I assume you have other searches (without unique ids) which you then select with "search1" and "search2".

0 Karma

tommywang
Explorer

Thanks, jeffland.
I find out that I can add id attribute of my search from 6.2. And that really makes sense.
Actually, before 6.2 (like 6.1), there is no id attribute of search, and splunk will give the id to search by default. The default id will be search1, search2...according to the sequence of searches.

0 Karma

tommywang
Explorer

PS. The version of my Splunk is 6.1. Doesn't is matter?

0 Karma

jeffland
SplunkTrust
SplunkTrust

Oh! Confer http://docs.splunk.com/Documentation/Splunk/6.1/Viz/PanelreferenceforSimplifiedXML to see that in 6.1, there is no such thing as an id attribute of your search. That is introduced later. Only your panels have ids, I don't know if you can access your search from the id of your panels.

Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...