<?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 Re: Java script modification help needed in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/523620#M35406</link>
    <description>&lt;P&gt;Any help would be highly Appreciable...&lt;/P&gt;</description>
    <pubDate>Thu, 08 Oct 2020 08:40:27 GMT</pubDate>
    <dc:creator>sbhatnagar88</dc:creator>
    <dc:date>2020-10-08T08:40:27Z</dc:date>
    <item>
      <title>Java script modification help needed</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/523163#M35369</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;We have been using below .js and .css file to create kind of feedback form in Splunk dashboard. Once feedback is submitted by user it get stored in feedback.csv . I need to add below two functionalities in feedback form.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. To add stars which has to be filled by user to record his satisfaction level.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp; when Send button is clicked after filling feedback, username should also get stored in feedback.csv.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is .js and .css file&lt;/P&gt;&lt;P&gt;--------- java script file----------&lt;/P&gt;&lt;PRE&gt;require(['splunkjs/mvc','splunkjs/mvc/searchmanager','splunkjs/mvc/simplexml/ready!'],function(mvc, SearchManager){
		var updateCSV = new SearchManager({
                id: "updateCSV",
                autostart: false,
		cache:false,
                search : "| makeresults | eval feedback=\"$setMsg$\" | inputlookup append=true feedback.csv | outputlookup feedback.csv"
                },{tokens: true});

	$(document).find('.dashboard-body').append('&amp;lt;button id="feedback" class="btn btn-primary"&amp;gt;Feedback&amp;lt;/button&amp;gt;');
	$(document).find('.dashboard-body').append('&amp;lt;div class="chat-popup" id="myForm"&amp;gt;&amp;lt;form class="form-container"&amp;gt;&amp;lt;h1&amp;gt;Feedback&amp;lt;/h1&amp;gt;&amp;lt;label for="msg"&amp;gt;&amp;lt;b&amp;gt;Message&amp;lt;/b&amp;gt;&amp;lt;/label&amp;gt;&amp;lt;textarea placeholder="Type Feedback.." name="msg" id="msgFeedback" required&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;span id="validationFeebback"&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;button id="sbmtFeedback" type="button" class="btn"&amp;gt;Send&amp;lt;/button&amp;gt;&amp;lt;button id="cnclFeebackPopUP" type="button" class="btn cancel"&amp;gt;Close&amp;lt;/button&amp;gt;&amp;lt;/form&amp;gt;&amp;lt;/div&amp;gt;');
	
	$("#feedback").on("click", function (){
		$('#msgFeedback').val("");
		$(document).find("#validationFeebback").text("");
		$(document).find('.chat-popup').show();
	});

	$("#cnclFeebackPopUP").on("click", function (){
		$(document).find('.chat-popup').hide();
	});

	$("#sbmtFeedback").on("click", function (){
		var msg=$('#msgFeedback').val();
		if (msg.length&amp;lt;=10 || (msg.length==1 &amp;amp;&amp;amp; msg==" ")){
			$(document).find("#validationFeebback").text("Invalid Feedback").css({'color':'red',});
		}
		else{
			var tokens = splunkjs.mvc.Components.get("default");
    			tokens.set("setMsg", msg);
			updateCSV.startSearch();
			$(document).find("#validationFeebback").text("Your feedback has been submitted..!").css({'color':'green'});
		}
	});
	
});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--------------------.css file-------------------&lt;/P&gt;&lt;PRE&gt;.chat-popup {
  display: none;
  position: fixed;
  bottom: 120px;
  border: 3px solid #f1f1f1;
  z-index: 9;
  margin-left: 30%;
}

/* Add styles to the form container */
.form-container {
  max-width: 300px;
  padding: 10px;
  background-color: white;
  min-width: 500px;
}

/* Full-width textarea */
.form-container textarea {
  width: 100%;
  padding: 15px;
  margin: 5px 0 22px 0;
  border: none;
  background: #f1f1f1;
  resize: none;
  min-height: 200px;
}

/* When the textarea gets focus, do something */
.form-container textarea:focus {
  background-color: #ddd;
  outline: none;
}

/* Set a style for the submit/send button */
.form-container .btn {
  background-color: #4CAF50;
  color: white;
  padding: 16px 20px;
  border: none;
  cursor: pointer;
  width: 100%;
  margin-bottom:10px;
  opacity: 0.8;
  line-height: 5px;
}

/* Add a red background color to the cancel button */
.form-container .cancel {
  background-color: red;
}

/* Add some hover effects to buttons */
.form-container .btn:hover, .open-button:hover {
  opacity: 1;
}
.btn-primary{
float:right;
}
.btn{
margin-right: 10px;
margin-top: 10px;
line-height: 25px;

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 11:40:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/523163#M35369</guid>
      <dc:creator>sbhatnagar88</dc:creator>
      <dc:date>2020-10-06T11:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Java script modification help needed</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/523620#M35406</link>
      <description>&lt;P&gt;Any help would be highly Appreciable...&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 08:40:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/523620#M35406</guid>
      <dc:creator>sbhatnagar88</dc:creator>
      <dc:date>2020-10-08T08:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: Java script modification help needed</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/524086#M35444</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/158927"&gt;@sbhatnagar88&lt;/a&gt;&amp;nbsp;for issue 1 you need a developer with JavaScript/jQuery knowledge (This is not a Splunk related issue). What have you tried to get Stars displayed in front-end? What has not worked?&lt;/P&gt;&lt;P&gt;For issue 2, writing to CSV is incorrect approach, ideally you should be writing to KVStore for this kind of use case not CSV.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Nevertheless, you can get the logged in Splunk User name by two approach:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Option 1.&lt;/STRONG&gt; Use environment token $env:user$ in Simple XML to set a token using Independent search.&amp;nbsp;&lt;BR /&gt;The following example explains the approach with an independent search to set the token &lt;STRONG&gt;loggedInUser&lt;/STRONG&gt; through SimpleXML and accesses token&amp;nbsp;&lt;STRONG&gt;loggedInUser&lt;/STRONG&gt; in JS using default or submitted token model. (you can find several examples for accessing tokens from change event handler of default and submitted token models in Splunk Dev or Splunk Answers.&amp;nbsp;&lt;A href="https://dev.splunk.com/enterprise/docs/developapps/visualizedata/binddatausingtokens/transformandvalidate/" target="_blank"&gt;https://dev.splunk.com/enterprise/docs/developapps/visualizedata/binddatausingtokens/transformandvalidate/&lt;/A&gt;)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;  &amp;lt;!-- Independent Search to get Logged in User Name --&amp;gt;
  &amp;lt;search&amp;gt;
    &amp;lt;query&amp;gt;| makeresults
| fields - _time 
| eval loggedInUser="$env:user$"
    &amp;lt;/query&amp;gt;
    &amp;lt;earliest&amp;gt;-1s&amp;lt;/earliest&amp;gt;
    &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;set token="loggedInUser"&amp;gt;$result.loggedInUser$&amp;lt;/set&amp;gt;
    &amp;lt;/done&amp;gt;
  &amp;lt;/search&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;Option 2&lt;/STRONG&gt;: Use&amp;nbsp;&lt;STRONG&gt;splunk.config&lt;/STRONG&gt;&amp;nbsp;library to access User Name from object&amp;nbsp;&lt;STRONG&gt;SplunkConfig['USERNAME']&lt;/STRONG&gt; &amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;require([
...
...
                'splunk.config'
            ], function(..., SplunkConfig) {
...
            	// Set the currently logged in user from Splunk Configuration to Token
                var username = SplunkConfig['USERNAME'];
...
});&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 11 Oct 2020 15:37:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Java-script-modification-help-needed/m-p/524086#M35444</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-10-11T15:37:57Z</dc:date>
    </item>
  </channel>
</rss>

