CXone Studio DBConnector returning empty JSON on first execution

Stumbled on a weird bug today with the DBConnector action in Studio. I am querying a custom table using SELECT * FROM user_prefs WHERE session_id = '${session.id}'. The first execution returns an empty JSON object {} even though the record exists. Subsequent runs return the correct payload, suggesting a caching issue on the connector level.

Is there a mandatory ClearCache step required before the lookup? I have tried adding a SetVariable delay but the Result.Data remains null on the initial trigger. The SQL syntax validates correctly in the UI tester.

The easiest fix here is this is to bypass the implicit caching behavior of the DBConnector by explicitly managing the query execution context or ensuring the session state is fully hydrated before the lookup occurs. In my experience with Genesys Cloud Studio, the DBConnector often relies on a cached session identifier that may not be populated during the very first tick of the flow, especially if the session.id is derived from a previous action that hasn’t fully committed its state yet.

Instead of relying on a ClearCache step, which is often ineffective for data connectors, you should implement a synchronous validation check. Add a SetVariable action immediately before the DBConnector to force the evaluation of ${session.id}. If the value is null or empty, trigger a fallback path. However, the more robust solution involves using the GetRESTProxy action with a direct SQL query endpoint if your DBConnector supports it, or ensuring the session.id is passed as a parameterized input rather than interpolated in the SQL string.

Here is the recommended configuration for the SetVariable pre-check:

{
 "name": "ValidateSessionId",
 "type": "SetVariable",
 "settings": {
 "variables": [
 {
 "name": "checkSession",
 "value": "${session.id != null && session.id != ''}",
 "dataType": "boolean"
 }
 ]
 }
}

Follow this with a Decision node checking checkSession. If false, wait 100ms using a Delay action to allow the platform to finalize the session object, then loop back. This avoids the race condition where the connector executes before the session metadata is fully attached to the call context. This pattern consistently resolves the empty JSON {} issue on first execution without requiring manual cache invalidation.