From f4952c76b86007f5b67f43b087a9190052066b38 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com> Date: Mon, 1 May 2023 10:54:42 -0700 Subject: [PATCH] Handle no matching account scenario (#22908) --- .../services/connection/browser/connectionWidget.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sql/workbench/services/connection/browser/connectionWidget.ts b/src/sql/workbench/services/connection/browser/connectionWidget.ts index e9bbd2fc3d..e0cae7637f 100644 --- a/src/sql/workbench/services/connection/browser/connectionWidget.ts +++ b/src/sql/workbench/services/connection/browser/connectionWidget.ts @@ -967,15 +967,18 @@ export class ConnectionWidget extends lifecycle.Disposable { if (accountName) { // For backwards compatibility with ADAL, we need to check if the account ID matches with tenant Id or just the account ID // The OR case can be removed once we no longer support ADAL - account = this._azureAccountList.find(account => account.key.accountId === this.getModelValue(accountName) + account = this._azureAccountList?.find(account => account.key.accountId === this.getModelValue(accountName) || account.key.accountId.split('.')[0] === this.getModelValue(accountName)); - this._azureAccountDropdown.selectWithOptionName(account.key.accountId); - } else { + if (account) { + this._azureAccountDropdown.selectWithOptionName(account.key.accountId); + } + } + if (!account) { // If account was not filled in from received configuration, select the first account. this._azureAccountDropdown.select(0); account = this._azureAccountList[0]; if (this._azureAccountList.length > 0) { - accountName = account.key.accountId; + accountName = account?.key?.accountId; } else { this._logService.debug('fillInConnectionInputs: No accounts available'); }