All Apps and Add-ons
Highlighted

How to assign a variable as a result of a search?

New Member

I have a very watered down search that pulls a string from a CSV file:

source="FILE.csv" host="HOSTSERVER" sourcetype="csv" "COLUMN NAME WITH SPACES IN CSV"="123" | table "COLUMN NAME WITH SPACES IN CSV"

Running this search returns a string as expected.

I would like to assign this value to a variable. The eval statement below is part of a larger search that builds a database query used in a dbxquery search:

eval STRINGBACK=[search source="FILE.csv" host="HOSTSERVER" sourcetype="csv" "COLUMN NAME WITH SPACES IN CSV"="123" | table "COLUMN NAME WITH SPACES IN CSV"]

When I try to run it, I get the error "Error in 'eval' command: Fields cannot be assigned a boolean result. Instead, try if([bool expr], [expr], [expr]). "

I did a tostring() on the STRINGBACK eval to see what is thought was coming back from the search, and it is "FALSE". I'm guessing I'm doing something pretty simple and foolish here to mess things up. Can anyone let me know what I am doing wrong? Thanks!

0 Karma
Highlighted

Re: How to assign a variable as a result of a search?

Legend

In an eval statement, strings have double-quotes ("string") and field names have single quotes ('field name'). So do this:

 eval STRINGBACK=[search source="FILE.csv" host="HOSTSERVER" sourcetype="csv" 'COLUMN NAME WITH SPACES IN CSV'="123" | table "COLUMN NAME WITH SPACES IN CSV"]

Or better

rename "COLUMN NAME WITH SPACES IN CSV" as new_name

and then just use the new name everywhere.

0 Karma