Asterisk: cdr with double function

In my extensions.conf I put those lines

same => n,set(CDR(nome)=${ODBC_Phonebook(${CALLERID(num)})})
same => n,set(CDR(nome)=${ODBC_Listanera_2(${CALLERID(num)})})

which recall those functions in func_odbc.conf


[Phonebook]
dsn=asterisk
readsql=Select CDRname from phonebook where CallerID='${ARG1}'

[Listanera]
dsn=asterisk
readsql=SELECT COUNT(*) FROM listanera WHERE callerid='${SQL_ESC(${ARG1})}'
synopsis=Controllo scocciatori

[Listanera_2]
dsn=asterisk
readsql=Select Nome from listanera where CallerID='${ARG1}'

Don’t works because the first overwrite the second (if invert happen the same thing, If I remove a name from a list appear a NULL value)

My idea is this

the caller is in blacklist, and in the cdr custom field “nome” appear his name, if is not in blacklist appear his name too (but is not kicked out of course!).
Any suggestion?

Solution found

On extensions.conf I use only one function


`same => n,set(CDR(nome)=${ODBC_Phonebook(${CALLERID(num)})})`

on func_odbc.conf I use this sql query

readsql=SELECT phonebook.CDRname from phonebook where phonebook.callerid='${ARG1}' union all select listanera.nome from listanera where listanera.callerid='${ARG1}'

so if a number is in “listanera” will take nome from listanera, if in phonebook take nome from phonebook otherwise null.

I don’t understand why you thought this would work.