Using the find command in a script

I’m writing a small script that I need to check for the existence of an item in the queue before execute a command. The command I am using is

:set vQName [/queue simple get [find name=“$xName”] name];

After this command I was going to compare xName to vQName to see if they are equal and branch depending on the result. However, if xName is NOT in the simple queue list, the script bombs with invalid argument.

I know the work around would be write a foreach loop and compare each name one at a time. But I thought the find command would be the more efficient way to go. Any ideas? Should I try to cut out the middle man and to the conditional statement right on the find command instead of saving it to a variable? If so, example please.

Thanks

:local xName "total"
:if ([:len [/queue simple find name=$xName]] = 1) do={
    :put "found"
}

or if you need the index of the queue

/queue simple {
    :local i [find name=$xName]
    :if ([:len $i] = 1) do={
        :put "found @$i"
    }
}

Thanks I’ll give them a try