Dashboards & Visualizations

Issue with Setting Default to Latest on Selection Change

juvenile
Loves-to-Learn

The default value of the product selection should be 'latest'. The token for the default value is determined by a hidden search for the latest product. This is dependent on the selected device. If the device selection changes, the product selection should revert to the default value, which is the latest product ID for the newly selected device. Currently, setting the latest product ID upon device change is not functioning. How can I resolve this issue?

 

<search id="base_search">
    <query>
        | mpreview index="my_index"
        | search key IN $token_device$
    </query>
    <earliest>$token_time.earliest$</earliest>
    <latest>$token_time.latest$</latest>
    <refresh>300</refresh>
</search>

<input id="select_device" type="dropdown" token="token_device" searchWhenChanged="true">
    <label>Device</label>

    <selectFirstChoice>true</selectFirstChoice>

    <prefix>(</prefix>
    <suffix>)</suffix>
    <valuePrefix>"</valuePrefix>
    <valueSuffix>"</valueSuffix>

    <search>
        <query>
            | mpreview index="my_index" 
            | stats count by key
            | fields key
            | lookup device-mapping.csv ...
            | fields key full_name
        </query>
    </search>
    <fieldForLabel>full_name</fieldForLabel>
    <fieldForValue>key</fieldForValue>

    <delimiter>,</delimiter>

    <change>
        <unset token="token_product"></unset>
        <unset token="form.token_product"></unset>
    </change>
</input>

<search>
    <query>
        | mpreview index="my_index"
        | search key IN $token_device$
        | stats latest(_time) as latest_time by product_id
        | sort -latest_time 
        | head 1 
        | fields product_id
    </query>
    <earliest>-24h@h</earliest>
    <latest>now</latest>

    <done>
        <condition match="$job.resultCount$ != 0">
            <set token="latest_product_id">$result.product_id$</set>
        </condition>
        <condition match="$job.resultCount$ == 0">
            <set token="latest_product_id">*</set>
        </condition>
    </done>
</search>

<input id="select_product" type="multiselect" token="token_product" searchWhenChanged="true">
    <label>Product</label>

    <default>$latest_product_id$</default>

    <prefix>(</prefix>
    <suffix>)</suffix>
    <valuePrefix>"</valuePrefix>
    <valueSuffix>"</valueSuffix>

    <choice value="*">All</choice>
    <search base="base_search">
        <query>
            | stats latest(_time) as latest_time by product_id
            | eventstats max(latest_time) as max_time 
            | eval label=if(latest_time == max_time, "latest", product_id) 
            | sort - latest_time
            | fields label, product_id
        </query>
    </search>
    <fieldForLabel>label</fieldForLabel>
    <fieldForValue>product_id</fieldForValue>

    <delimiter>,</delimiter>

    <change>
        <condition label="All">
            <set token="token_product">("*") AND product_id != "LoremIpsum"</set>
        </condition>
    </change>
</input>

 

Labels (1)
0 Karma
Get Updates on the Splunk Community!

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...

SignalFlow: What? Why? How?

What is SignalFlow? Splunk Observability Cloud’s analytics engine, SignalFlow, opens up a world of in-depth ...