Splunk Search

Replace only if commas exist

treverce
Explorer

I have a dashboard (form) that I'm trying to allow a text field to accept single values or comma separated values that will be replaced by "* OR" right now when I first start up the dashboard and enter a single value, it just stays at "Search is waiting for input.." if I enter comma separated values it will run the search. I tried rapping the eval in a if statement to check for commas, but that didn't seem to do anything.

Here is what I currently have:

<input type="text" token="clientTransactionId" searchWhenChanged="true" id="webOrder">
        <label>Transaction Id (for multiple use csv's):</label>
        <change>
          <eval token="clientTransactionId_formatted">if(like($clientTransactionId$, "%,%"),replace($clientTransactionId$,",","* OR"),$clientTransactionId$)</eval>
        </change>
      </input>

And here is what I tried before:

<eval token="clientTransactionId_formatted">replace($clientTransactionId$,",","* OR")</eval>

How can I set this up to run? I need it to eval before search, there are too many transactions to filter after search has ran.

Thanks!

0 Karma

manjunathmeti
Champion

Your code looks good and below statement is enough, replace occurs only if "," present in input otherwise clientTransactionId_formatted set to clientTransactionId. Can you post xml part of where token clientTransactionId_formatted is used.

<eval token="clientTransactionId_formatted">replace($clientTransactionId$,",","* OR")</eval>
0 Karma

treverce
Explorer

This is what I have right now:

<search>
  <query>
    index=[redacted] (source="[redacted]*" OR source="[redacted]*") $clientTransactionId_formatted$* $actionType$ earliest=$date_range$ latest=now ...
  </query>
  <earliest>-7d@h</earliest>
  <latest>now</latest>
  <sampleRatio>1</sampleRatio>
</search>

(Sorry I had to redact things for company security/privacy)

0 Karma

treverce
Explorer

The more I play with it the more it seems this only happens if its a SINGLE transaction on the first query after I load the page, if I start with csv's then it works first start, just not when its the first query of a single transaction.

0 Karma

treverce
Explorer

I think I see what is causing the issue, I have a second input (multi select) and if its "populating" when I enter into the first one, it doesn't trigger the eval. Not sure why those would be dependent one one another. I have a few static options defined, such as an "All" which is a * value as default.

If I wait until after "populating" is completed, it works.

<input type="multiselect" token="actionType" searchWhenChanged="true" id="action">
  <label>Action Type:</label>
  <choice value="*">All</choice>
  <choice value="">------------------------------------------</choice>
  <valuePrefix>"actionType:
  </valuePrefix>
  <delimiter>
    OR
  </delimiter>
  <fieldForLabel>ACTION_TYPE</fieldForLabel>
  <fieldForValue>ACTION_TYPE</fieldForValue>
  <search>
    <query>[REDACTED]</query>
    <earliest>-5m</earliest>
    <latest>now</latest>
  </search>
  <valueSuffix>"</valueSuffix>
  <default>*</default>
</input>
0 Karma

manjunathmeti
Champion

Is searchWhenChanged="true" set for other token inputs? Are you using Submit button? I don't see any issue with this text input. You can use below xml, it gives output for single value also.

<form>
  <fieldset submitButton="false">
    <input type="text" token="clientTransactionId" searchWhenChanged="true" id="webOrder">
      <label>Transaction Id (for multiple use csv's):</label>
      <change>
        <eval token="clientTransactionId_formatted">replace($clientTransactionId$,",","* OR ")</eval>
      </change>
    </input>
  </fieldset>
  <row>
    <html>
          <h3>Token:</h3>
          <div class="custom-result-value">$clientTransactionId_formatted$</div>
      </html>
  </row>
</form>
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...