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!

Unlock New Opportunities with Splunk Education: Explore Our Latest Courses!

At Splunk Education, we’re dedicated to providing top-tier learning experiences that cater to every skill ...

Technical Workshop Series: Splunk Data Management and SPL2 | Register here!

Hey, Splunk Community! Ready to take your data management skills to the next level? Join us for a 3-part ...

Spotting Financial Fraud in the Haystack: A Guide to Behavioral Analytics with Splunk

In today's digital financial ecosystem, security teams face an unprecedented challenge. The sheer volume of ...