Splunk Dev

Javascript Submit button not executing SPL search

ChrisChalmers01
Explorer

I am trying to create a dashboard that contains a textbox. When a ticket reference is given to the textbox and a user clicks submit, a search is run in the background that appends the ticket information to a kvstore.

This is my dashboard -

 

<form script="run_action.js">
  <label>QA Manual Submission</label>
  <description>A dashboard that allows for the manual submission of QA Samples.</description>
  <fieldset submitButton="false"></fieldset>
  <row>
    <panel>
      <input type="text" token="tokRef" searchWhenChanged="true">
        <label>Ticket Reference</label>
        <default>[Letter][number]_SOC</default>
        <initialValue>[Letter][number]_SOC</initialValue>
      </input>
      <html>
        <p>Click "Add to QA" to manually add the ticket number to the QA App</p>
        <button class="btn btn-primary button1">Add to QA</button>
      </html>
    </panel>
  </row>
</form>

 

This is javascript I am using -

 

         require([
            "jquery",
            "splunkjs/mvc",
            "splunkjs/mvc/searchmanager",
            "splunkjs/mvc/tableview",
            "splunkjs/mvc/textinputview",
            "splunkjs/mvc/simplexml/ready!"
          ],function(
              mvc,
              $,
              SearchManager,
              TableView,
              TextInputView
          ) {
              
              //debug testing
              console.log("I get this far!");
              //Add after some research on Splunk Anwsers. Since removed.
              //var SearchManager = require("splunkjs/mvc");
              //var SearchManager = require("splunkjs/mvc/searchmanager");
              //var TextInputView = require("splunkjs/mvc/textinputview");
              //var TableView = require("splunkjs/mvc/tableview");
              //var $ = require("jquery");
              
              var mysearch = new SearchManager({
                  id: "mysearch",
                  autostart: "false",
                  search: mvc.tokenSafe("| jira jqlsearch \"project IN projectMatch(\\\".+_SOC.+\\\") AND assignee was in(membersOf(\"GG_JIRA_Filter\")) AND status=Closed AND created >= startOfMonth()\" fields \"project,summary,status,resolution,resolutiondate,updated,created,issuetype,assignee\" \r\n| table Summary, Key, \"Issue Type\", Resolution, Assignee, Resolved, Created, \"QA Commentary\", \"QA By\", \"Perceived Ticket Quality\", \"QA Pass\/Fail\"\r\n| rename Key as Ticket_Ref, \"Issue Type\" As Issue_Type\r\n| rex field=Resolved \"(?<date>\\d{4}\\-\\d{2}\\-\\d{2})T(?<time>\\d{2}:\\d{2}:\\d{2})\" \r\n| eval extracted_time=date+\" \"+time \r\n| eval Resolved=strptime(extracted_time,\"%Y-%m-%d %H:%M:%S\") \r\n| eval Resolved=round(Resolved,0) \r\n| rex field=Created \"(?<created_date>\\d{4}\\-\\d{2}\\-\\d{2})T(?<created_time>\\d{2}:\\d{2}:\\d{2})\" \r\n| eval created_extracted_time=created_date+\" \"+created_time \r\n| eval Created=strptime(created_extracted_time,\"%Y-%m-%d %H:%M:%S\") \r\n| eval Created=round(Created,0)\r\n| table Ticket_Ref, Summary, \"Issue_Type\", Resolution, Assignee, Resolved, Created, \"QA Commentary\", \"QA By\", \"Perceived Ticket Quality\", \"QA Pass\/Fail\", \"Manual QA Add\"\r\n| eval \"Manual QAA dd\"=\"True\"\r\n|  search Ticket_Ref=$tokRef$\r\n| outputlookup qa_lookup append=True")                
                });

              $(".button1").on("click", function (){
                  var ok = confirm("Are you sure?");
                  if (ok){
                      mysearch.startSearch();
                      alert('attempted restart!');
                  } //else {
                  //    alert('user did not click ok!');
                  //}
              });
            });

 

When I try to run the dashboard I get the following errors on the console -

ChrisChalmers01_0-1629212902812.png


Limited knowledge of JS and I've done my best to follow guidance on splunk anwsers. Would appreciate any insight.

Many thanks

Christopher

Labels (3)
0 Karma
1 Solution

ChrisChalmers01
Explorer

I managed to solve the issue - it was actually an SPL problem as appose to JS. The Query had a mistake in it! Once I fixed this the issue disappeared. Thank you for the input @alucarddjin !

View solution in original post

0 Karma

alucarddjin
Path Finder

I think the issue is with your order at the start

        require([
            "jquery", #1st
            "splunkjs/mvc", #2nd
            "splunkjs/mvc/searchmanager", #3rd
            "splunkjs/mvc/simplexml/ready!"
          ],function(
              mvc, #1st (jquery)
              $, #2nd (mvc)
              SearchManager #3rd (searchmanager)
          

 

You've got jQuery first in your requires but second in the function to mvc is mapping to the jQuery object and $ is mapping to the mvc. In your function section if you change them around so they go  $, mvc, it should sort out your issue.

ChrisChalmers01
Explorer

I managed to solve the issue - it was actually an SPL problem as appose to JS. The Query had a mistake in it! Once I fixed this the issue disappeared. Thank you for the input @alucarddjin !

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...