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!

Cloud Platform & Enterprise: Classic Dashboard Export Feature Deprecation

As of Splunk Cloud Platform 9.3.2408 and Splunk Enterprise 9.4, classic dashboard export features are now ...

Explore the Latest Educational Offerings from Splunk (November Releases)

At Splunk Education, we are committed to providing a robust learning experience for all users, regardless of ...

New This Month in Splunk Observability Cloud - Metrics Usage Analytics, Enhanced K8s ...

The latest enhancements across the Splunk Observability portfolio deliver greater flexibility, better data and ...