Running into a snag with the DBConnector action in a CXone Studio script. The goal is straightforward: look up a customer record based on an inbound phone number and then branch logic based on whether that record exists. The SQL query is simple enough, just a SELECT id, status FROM customers WHERE phone = :inbound_phone.
The issue is how Studio handles the response when no rows match. I’m assigning the output to a session variable dbResult. When a match is found, dbResult contains the expected JSON object. When there’s no match, the variable seems to be null or undefined, but subsequent actions that reference dbResult.id throw a generic runtime error instead of gracefully handling the missing data.
Here’s the snippet of the Studio configuration for the DBConnector action:
{
"action": "DBConnector",
"connectionName": "prod_db_conn",
"queryType": "SELECT",
"sql": "SELECT id, status FROM customers WHERE phone = :inbound_phone",
"parameters": {
"inbound_phone": "{session.inbound_phone}"
},
"outputVariable": "dbResult"
}
And the immediate next action is an IF statement checking dbResult.id. It crashes the flow with this error payload in the logs:
{
"timestamp": "2023-10-27T14:30:00Z",
"error": "Cannot read property 'id' of undefined",
"action": "IF_Check_Customer",
"sessionId": "sess_12345"
}
I’ve tried wrapping it in a try-catch block using a JavaScript snippet action, but Studio’s execution engine doesn’t seem to allow custom JS in the main flow control for this specific connector type. Is there a standard way to check if the DBConnector returned an empty set before trying to access properties on the result object? Or do I need to structure the SQL query to always return a dummy row if no match is found? That feels like a hack. Looking for the cleanest approach to handle null results from DBConnector in Studio.