Hi,
In the script you have set the DNIS that is the called number and the called number here is the CTI RP which invokes this script and hence the results return the CTI RP number
Instead of DNIS please set the attribut to calling number and then check if you get the correct results.
Also make sure that the variable that you defined for calling number is set as string type.
HTH
Please rate this reply
Rajiv