diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 1cc5c295ac06..0c34f301f3ef 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -1622,9 +1622,14 @@ function createAndOpenSearchTransactionThread( // For legacy transactions without an IOU action in the backend, pass transaction data // This allows OpenReport to create the IOU action and transaction thread on the backend const reportActionID = moneyRequestReportActionID ?? iouReportAction?.reportActionID; - const transaction = !reportActionID ? getTransactionFromTransactionListItem(item) : undefined; - const transactionViolations = !reportActionID ? item.violations : undefined; - transactionThreadReport = createTransactionThreadReport(item.report, {reportActionID} as OnyxTypes.ReportAction, transaction, transactionViolations); + // Pass transaction data when there's no reportActionID OR when the item is from self DM + // (unreported transactions have a valid reportActionID but still need transaction data for proper detection) + const shouldPassTransactionData = !reportActionID || isFromSelfDM; + const transaction = shouldPassTransactionData ? getTransactionFromTransactionListItem(item) : undefined; + const transactionViolations = shouldPassTransactionData ? item.violations : undefined; + // Use the full reportAction to preserve originalMessage.type (e.g., "track") for proper expense type detection + const reportActionToPass = iouReportAction ?? item.reportAction ?? ({reportActionID} as OnyxTypes.ReportAction); + transactionThreadReport = createTransactionThreadReport(item.report, reportActionToPass, transaction, transactionViolations); } if (shouldNavigate) { diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index 8b8f79a025b8..dd885cd8b4ef 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -3249,7 +3249,8 @@ describe('SearchUIUtils', () => { SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, backTo, threadReportID, undefined, false); expect(setOptimisticDataForTransactionThreadPreview).toHaveBeenCalled(); - expect(createTransactionThreadReport).toHaveBeenCalledWith(report1, {reportActionID: '11111111'}, undefined, undefined); + // The full reportAction is passed to preserve originalMessage.type for proper expense type detection + expect(createTransactionThreadReport).toHaveBeenCalledWith(report1, reportAction1, undefined, undefined); }); test('Should not navigate if shouldNavigate = false', () => {