Dashboards & Visualizations

How to conditionally display HTML panels with a token, set via a javascript program?

snipedown21
Path Finder

I have a fair idea that depends="$token$" can be used to display or hide the panel. My requirement is that I get the list of roles for a user, via a Javascript file, and load it onto tokens present on the dashboard.

Now, these tokens will be set to "null" when the dashboard initially loads, and from the script, set to the role value.

The dashboard itself is filled with panels which I need to conditionally display based on the roles returned from the search.

Here is some code I have put together:

<dashboard script="set_permissions.js" hideFooter="true" hideSplunkBar="true" hideEdit="false">
  <label>Title</label>
  <description>trying to render based on token setting from JS</description>
  <fieldset submitButton="false">
    <input type="dropdown" token="role1"></input>
  </fieldset>
  <row>
    <panel depends="$role1$">
      <html src="content.html">
      </html>
    </panel>
  </row>
</dashboard>

I also have CSS attached to the dashboard
And, here is the JS code:

require([
     "jquery",
     "splunkjs/mvc",
     "splunkjs/mvc/simplexml/ready!"
     ], function(
         $,
        mvc
     ) {
        var tokens = mvc.Components.get("default");
        var permissionGrant = "power";
    tokens.set("role1", permissionGrant);
     });

So, summarizing, the JS will set the token "role1" with a value from a search(In the example I have hardcoded the value).
The panel will then make a request and get the relevant HTML page and render it.

Thanks in advance.
Splunk for Life 🙂

Tags (1)
0 Karma
1 Solution

niketn
Legend

@snipedown21, seems like you need to setup role based access/display in Splunk Dashboard using JavaScript. Refer to one of my older answers on similar lines which you can re-use as per your use case: https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html

Kindly try out and let us know if you need further assistance.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@snipedown21, seems like you need to setup role based access/display in Splunk Dashboard using JavaScript. Refer to one of my older answers on similar lines which you can re-use as per your use case: https://answers.splunk.com/answers/575377/can-i-restrict-permissions-for-the-text-box-drilld.html

Kindly try out and let us know if you need further assistance.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

snipedown21
Path Finder

@niketnilay, the link provides exactly what I need. Thank you for the super fast and accurate response.
There was really no need for javascript.

niketn
Legend

@snipedown21 I have converted my comment to answer. Please accept the same to mark this as answered!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

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