Dashboards & Visualizations

how to change search query on change datetime ?

sfatnass
Contributor

i have two different search queries for the same panel, and i need to switch between them when date change :

function switchQuery(){
var mySearch = "";
 if(mycondition1) {

        mySearch = "index = first |........";
    }else {
         mySearch = "index = second | ..........";

    };
    return mySearch;
    }
}

this is my searchmanager :

  var mysearchID = new SearchManager({
            "id": "mysearchID",
            "earliest_time": "$formTimeEarliest$",
            "cancelOnUnload": true,
            "search": switchQuery(),
            "status_buckets": 0,
            "latest_time": "$formTimeLatest$",
            "app": utils.getCurrentApp(),
            "auto_cancel": 90,
            "preview": true,
            "runWhenTimeIsUndefined": false,
            "autostart": true
        }, {
            tokens: true
        });

this is the function on change for my datepicker :

datePicker.on("change", function (newValue) {
        FormUtils.handleValueChange(datePicker);

        //when i call switchQuery() here, the variable mySearch change but the search query not 

    });

i don't know how can i do that and it's really important to do something like this and i can't add the searchManager inside my function swithQuery(), because i get an error "already exist mysearchID".

thx

0 Karma

DalJeanis
Legend

There is some pretty clear example code here - http://dev.splunk.com/view/webframework-codeexamples/SP-CAAAE5V

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...