Dashboards & Visualizations

script

SN1
Path Finder

So I am using this script , what this script does it it creates a solved button on each field of dashboard drilldown and when that button it clicked it changes the value of solved field to 1 from 0 . I wan to know whats wrong in this script button can be seen but when it is clicked nothing happens even if i refresh the drilldown.

This is the drilldown with the button in rowKey field.

SN1_0-1750221054876.png


This is the script.

require([
'splunkjs/mvc',
'splunkjs/mvc/searchmanager',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!',
'jquery'
], function(mvc, SearchManager, TableView, ignored, $) {

// Define a simple cell renderer with a button
var ActionButtonRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
return cell.field === 'rowKey';
},
render: function($td, cell) {
$td.addClass('button-cell');


var rowKey = cell.value
var $btn = $('<button class="btn btn-success">Mark Solved</button>');

$btn.on('click', function(e) {
e.preventDefault();
e.stopPropagation();

var searchQuery = `| inputlookup sbc_warning.csv
| eval rowKey=tostring(rowKey)
| eval solved=if(rowKey="${rowKey}", "1", solved)
| outputlookup sbc_warning.csv`;

var writeSearch = new SearchManager({
id: "writeSearch_" + Math.floor(Math.random() * 100000),
search: searchQuery,
autostart: true
});

writeSearch.on('search:done', function() {
console.log("Search completed and lookup updated");
var panelSearch = mvc.Components.get('panel_search_id');
if (panelSearch) {
panelSearch.startSearch();
console.log("Panel search restarted");
}
});
});

$td.append($btn);
}
});

// Apply the renderer to the specified table
var tableComponent = mvc.Components.get('sbc_alarm_table');
if (tableComponent) {
tableComponent.getVisualization(function(tableView) {
tableView.table.addCellRenderer(new ActionButtonRenderer());
tableView.table.render();
});
}
});
Labels (1)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @SN1 

I would start by adding a console.log(rowKey); and also one after searchQuery - console.log(searchQuery);

and then validate that these are outputting what you expect.

Can you check to see if this prints out what you are expecting and let us know how you get on as this might help drill down further.

🌟 Did this answer help you? If so, please consider:

  • Adding karma to show it was useful
  • Marking it as the solution if it resolved your issue
  • Commenting if you need any clarification

Your feedback encourages the volunteers in this community to continue contributing

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...