Splunk Search

How to pass Panels XML dynamically to Splunk XML Dashboard using Javascript?

ericaooi
Explorer

Hi,

I would like to have a xml panels code to be passed from Javascript to Splunk XML code dynamically.
For instance, by default, the XML dashboard has 2 panels. After that, when javascript file is executed, the panels will be added dynamically accordingly to the conditions of the user to have 3 or more panels based on conditions.

I have tried to passed the XML panel code from Javascript as a token to XML code but the Dashboard does not display the panel in Dashboard. Following is a sample code I have.

XML

<dashboard>
.......

<row>
       $table1$
</row>
........
</dashboard>

 

Javascript

const panel = '<panel><table><search><query>index=_internal  | stats count by sourcetype</query><earliest>-24h@h</earliest><latest>now</latest><sampleRatio>1</sampleRatio></search><option name="count">20</option><option name="dataOverlayMode">none</option><option name="drilldown">none</option><option name="percentagesRow">false</option><option name="rowNumbers">false</option><option name="totalsRow">false</option><option name="wrap">true</option></table></panel>'
        var parser = new DOMParser();
        var xmlDoc = parser.parseFromString(panel, "text/xml"); //important to use "text/xml"
        tokens.set("table1", xmlDoc.documentElement);
        submitted_tokens.set(tokens.toJSON());

 

May I know how to solve this, please?

Thank you in advance.

 

Labels (1)
Tags (1)
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...