<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Splunkjs - access field names from search data object. in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130075#M1849</link>
    <description>&lt;P&gt;Hoping I'll be able to find an answer to this; any help is much appreciated.&lt;/P&gt;

&lt;P&gt;I'm running a search and then populating a custom chart made with Google Charts.&lt;/P&gt;

&lt;P&gt;I have no problems getting the results back from a search (as below), but is there a way of returning the field names from the search ? The reason for this is so I can apply these as axis titles (rather than manually set them). Hopefully this makes sense.&lt;/P&gt;

&lt;P&gt;var mySearch = splunkjs.mvc.Components.getInstance("search3");&lt;BR /&gt;
var datasource = mySearch.data('results', {count:0});&lt;BR /&gt;
console.log("Rows: ", datasource.data().rows);&lt;/P&gt;</description>
    <pubDate>Mon, 24 Nov 2014 11:23:02 GMT</pubDate>
    <dc:creator>peamc</dc:creator>
    <dc:date>2014-11-24T11:23:02Z</dc:date>
    <item>
      <title>Splunkjs - access field names from search data object.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130075#M1849</link>
      <description>&lt;P&gt;Hoping I'll be able to find an answer to this; any help is much appreciated.&lt;/P&gt;

&lt;P&gt;I'm running a search and then populating a custom chart made with Google Charts.&lt;/P&gt;

&lt;P&gt;I have no problems getting the results back from a search (as below), but is there a way of returning the field names from the search ? The reason for this is so I can apply these as axis titles (rather than manually set them). Hopefully this makes sense.&lt;/P&gt;

&lt;P&gt;var mySearch = splunkjs.mvc.Components.getInstance("search3");&lt;BR /&gt;
var datasource = mySearch.data('results', {count:0});&lt;BR /&gt;
console.log("Rows: ", datasource.data().rows);&lt;/P&gt;</description>
      <pubDate>Mon, 24 Nov 2014 11:23:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130075#M1849</guid>
      <dc:creator>peamc</dc:creator>
      <dc:date>2014-11-24T11:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Splunkjs - access field names from search data object.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130076#M1850</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;if you console.log(datasource.data()), you will see an array that contains the fields. So you can use this to also print out the fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var mySearch = splunkjs.mvc.Components.getInstance("search3");
var datasource = mySearch.data('results', {count:0});
console.log("Rows: ", datasource.data().rows); 
console.log("Fields: ", datasource.data().fields); 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Greetings&lt;/P&gt;

&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 24 Nov 2014 13:54:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130076#M1850</guid>
      <dc:creator>tom_frotscher</dc:creator>
      <dc:date>2014-11-24T13:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: Splunkjs - access field names from search data object.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130077#M1851</link>
      <description>&lt;P&gt;Thanks, Tom.&lt;/P&gt;

&lt;P&gt;That worked perfectly !&lt;/P&gt;</description>
      <pubDate>Mon, 24 Nov 2014 14:54:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130077#M1851</guid>
      <dc:creator>peamc</dc:creator>
      <dc:date>2014-11-24T14:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splunkjs - access field names from search data object.</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130078#M1852</link>
      <description>&lt;P&gt;i tried using this to retrieve field header names so that i can put it on the a dropdown list. but i always keep on getting  Uncaught TypeError: Cannot read property 'rows' of undefined, which ID should I use? the ID for the search bar or the ID of the search manager? or am I lacking on js libraries? &lt;/P&gt;

&lt;P&gt;here's  my script&lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
    "splunkjs/mvc/searchmanager",&lt;BR /&gt;
    "splunkjs/mvc/searchbarview",&lt;BR /&gt;
    "splunkjs/mvc/searchcontrolsview",&lt;BR /&gt;
    "splunkjs/mvc/timelineview",&lt;BR /&gt;
    "splunkjs/mvc/tableview",&lt;BR /&gt;
    "splunkjs/mvc/simplexml/ready!"&lt;BR /&gt;
], function(&lt;BR /&gt;
    SearchManager,&lt;BR /&gt;
    SearchbarView, &lt;BR /&gt;
    SearchControlsView, &lt;BR /&gt;
    TimelineView, &lt;BR /&gt;
    TableView&lt;BR /&gt;
) {&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;// Create the search manager
var mysearch = new SearchManager({
    id: "search1",
    app: "search",
    preview: true,
    cache: true,
    status_buckets: 300,
    required_field_list: "*",
    search: "index=_internal | head 100"
});

// Create the views
var mytimeline = new TimelineView ({
    id: "timeline1",
    managerid: "search1",
    el: $("#mytimeline1")
}).render();

var mysearchbar = new SearchbarView ({
    id: "searchbar1",
    managerid: "search1",
    el: $("#mysearchbar1")
}).render();

var mysearchcontrols = new SearchControlsView ({
    id: "searchcontrols1",
    managerid: "search1",
    el: $("#mysearchcontrols1")
}).render();

var mytable = new TableView ({
    id: "table1",
    managerid: "search1",
    el: $("#mytable1")
}).render();

// When the timeline changes, update the search manager
mytimeline.on("change", function() {
    mysearch.settings.set(mytimeline.val());
});

// When the query in the searchbar changes, update the search manager
mysearchbar.on("change", function() {
    mysearch.settings.unset("search");
    mysearch.settings.set("search", mysearchbar.val());
});

// When the timerange in the searchbar changes, update the search manager
mysearchbar.timerange.on("change", function() {
    mysearch.settings.set(mysearchbar.timerange.val());
});

 var searchRes = splunkjs.mvc.Components.getInstance("search1");
 var datasource = searchRes.data('results', {count:});
 console.log("Rows: ", datasource.data().rows); 
 console.log("Fields: ", datasource.data().fields); 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;});&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2018 02:02:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Splunkjs-access-field-names-from-search-data-object/m-p/130078#M1852</guid>
      <dc:creator>japposadas</dc:creator>
      <dc:date>2018-01-23T02:02:20Z</dc:date>
    </item>
  </channel>
</rss>

