Skip to content

Add mappable Unique ID field to company card CSV import - #99201

Open
tgolen wants to merge 2 commits into
mainfrom
tgolenViaClaude/github-issue-99195-43600a
Open

Add mappable Unique ID field to company card CSV import#99201
tgolen wants to merge 2 commits into
mainfrom
tgolenViaClaude/github-issue-99195-43600a

Conversation

@tgolen

@tgolen tgolen commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Expensify Classic's domain company-card CSV upload lets you map a Unique ID column that acts as a dedup key, so re-uploading the same (or an overlapping) file skips rows you've already imported. New Expensify's company card CSV import had no such field, so every re-import created duplicate transactions.

A saved externalID mapping is deliberately never restored on a later import. The import appends a synthetic externalID column whenever the user maps no Unique ID, and the persisted index is then indistinguishable from a Unique ID mapped to the last column (both look like "externalID":"5" on a six-column layout), so restoring it could point Unique ID at an unrelated column whose repeated values would make the backend dedupe valid transactions. Re-mapping it by hand is the safe behavior until the backend can distinguish the two.

Fixed Issues

$ #99195

Tests

Note

For testing on a local environment, you might need to refer to this SO to get your uploads working

company-cards-unique-id-last-column.csv

  1. Open a workspace and go to Company cardsAdd cards.
  2. Select United States, then choose Import transactions from file.
  3. Enter a company card layout name and turn Use advanced fields on.
  4. Click Next and upload the CSV from above that has a column of unique IDs, with that column in any position other than the first. There is a bug in the scrapers if the unique ID column is in the first column, fixed by PR https://github.com/Expensify/Server-Scraper/pull/4407
  5. On the mapping screen, open the dropdown for that column and verify Unique ID appears in the list.
  6. Map Unique ID to the ID column, and map the card number, date, merchant, amount, and currency columns.
  7. Map Unique ID to a second column as well, and verify the existing "mapped a single field to multiple columns" error appears. Undo that second mapping.
  8. Click Import, assign the card to yourself (selecting a start date before 2024), and verify the transactions appear on the spend page
  9. Repeat steps 1-8 with the exact same file, mapping Unique ID the same way, and verify no duplicate transactions were created.
  10. Change one row's Unique ID value to a new value, import again, and verify only that row is added.
  11. Repeat steps 1-8 with Use advanced fields off, and verify Unique ID is not offered and re-importing still creates duplicates (unchanged existing behavior).
  12. Import a file with no Unique ID mapped, then re-import from the feed's SettingsImport spreadsheet with a file that has more columns, and verify no column is auto-mapped as Unique ID.
  • Verify that no errors appear in the JS console

Offline tests

This change does not alter offline behavior. The mapping screen renders from the locally parsed spreadsheet, and the import itself uses the existing ImportCSVCompanyCards write, which queues like any other write while offline.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari image image

Use a mapped Unique ID column as the transaction externalID instead of
generating a fresh rand64() per row on every import, so the existing backend
dedup in Transaction::isExternalDupe can match and re-uploads stop creating
duplicates. Falls back to a generated ID when the column is unmapped or a
row's cell is blank, leaving existing behavior unchanged.

Also treats externalID as an advanced column when deciding whether a re-import
from feed settings re-enables the advanced fields, so the mapping survives the
re-upload it exists for.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@OSBotify

Copy link
Copy Markdown
Contributor

🦜 Polyglot Parrot! 🦜

Squawk! Looks like you added some shiny new English strings. Allow me to parrot them back to you in other tongues:

View the translation diff
diff --git a/src/languages/es.ts b/src/languages/es.ts
index d986a169..5a3db2fe 100644
--- a/src/languages/es.ts
+++ b/src/languages/es.ts
@@ -5827,7 +5827,7 @@ ${amount} para ${merchant} - ${date}`,
                     comment: 'Comentario',
                     category: 'Categoría',
                     tag: 'Etiqueta',
-                    uniqueID: 'ID único',
+                    uniqueID: 'ID única',
                 },
                 csvErrors: {
                     requiredColumns: (missingColumns: string) => `Por favor, asigna una columna a cada uno de los atributos: ${missingColumns}.`,
diff --git a/src/languages/ja.ts b/src/languages/ja.ts
index 5eae494b..0d3d15d3 100644
--- a/src/languages/ja.ts
+++ b/src/languages/ja.ts
@@ -5861,7 +5861,7 @@ _詳しい手順については、[ヘルプサイトをご覧ください](${CO
                     comment: 'コメント',
                     category: 'カテゴリ',
                     tag: 'タグ',
-                    uniqueID: '一意のID',
+                    uniqueID: '一意の ID',
                 },
                 csvErrors: {
                     requiredColumns: (missingColumns: string) => `各属性に列を割り当ててください:${missingColumns}`,
diff --git a/src/languages/pt-BR.ts b/src/languages/pt-BR.ts
index b01defd7..316e1235 100644
--- a/src/languages/pt-BR.ts
+++ b/src/languages/pt-BR.ts
@@ -5917,7 +5917,7 @@ _Para instruções mais detalhadas, [visite nossa central de ajuda](${CONST.NETS
                     comment: 'Comentário',
                     category: 'Categoria',
                     tag: 'Etiqueta',
-                    uniqueID: 'ID único',
+                    uniqueID: 'ID exclusivo',
                 },
                 csvErrors: {
                     requiredColumns: (missingColumns: string) => `Atribua uma coluna a cada um dos atributos: ${missingColumns}.`,

Note

You can apply these changes to your branch by copying the patch to your clipboard, then running pbpaste | git apply 😉

View workflow run

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/actions/CompanyCards.ts 37.15% <100.00%> (+3.41%) ⬆️
src/libs/actions/ImportSpreadsheet.ts 80.00% <100.00%> (+0.48%) ⬆️
...e/companyCards/addNew/CompanyCardsImportedPage.tsx 0.00% <0.00%> (ø)
... and 80 files with indirect coverage changes

@tgolen
tgolen marked this pull request as ready for review August 21, 2026 17:27
@tgolen
tgolen requested review from a team as code owners August 21, 2026 17:27
@melvin-bot
melvin-bot Bot requested a review from marufsharifi August 21, 2026 17:27
@melvin-bot

melvin-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

@marufsharifi Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef3d90b3ad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

CONST.CSV_IMPORT_COLUMNS.COMMENT,
CONST.CSV_IMPORT_COLUMNS.CATEGORY,
CONST.CSV_IMPORT_COLUMNS.TAG,
CONST.CSV_IMPORT_COLUMNS.EXTERNAL_ID,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Distinguish generated IDs from advanced-field mappings

The import action appends externalID to the submitted mappings whenever the user does not select a Unique ID, so persisted layouts can contain this key even when advanced fields were disabled. Treating every stored externalID as advanced makes re-imports of those basic feeds enable advanced fields; worse, if a later spreadsheet has a real column at the formerly synthetic index, applyCompanyCardSavedColumnMappings automatically maps that unrelated column as the Unique ID, and repeated values can cause valid transactions to be deduplicated. Determine whether the stored mapping corresponds to an actual source column before using it to infer advanced mode.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, and confirmed against real data rather than reasoning. The persisted layout for a feed imported on a dev VM is:

"uploadLayoutSettings":{"columnMappings":{"cardNumber":"0","postedDate":"1","merchant":"2","amount":"3","currency":"4","externalID":"5"},"instanceID":"1787332070659"}

That externalID: "5" came from a column the user really mapped, but a synthetic one is indistinguishable: the append puts it at index = column count, so a five-column basic feed persists externalID: "5" too. No client-side signal separates the two cases, so inferring anything from a stored externalID index is unsafe — including the auto-map, which could have pointed Unique ID at an unrelated column and let repeated values dedupe valid transactions.

Fixed in e771bca:

  • Reverted EXTERNAL_ID from ADVANCED_CSV_COLUMNS, so a basic feed no longer re-imports in advanced mode.
  • applyCompanyCardSavedColumnMappings now skips saved externalID mappings outright, with a test that fails when the guard is removed.

The tradeoff is that the re-import-from-feed-settings path cannot restore a Unique ID mapping, so the user re-maps it. That is strictly better than silently mis-mapping the dedup key, and properly distinguishing a user-mapped externalID from the synthetic one needs a backend signal — part of the "add advanced fields to an existing feed" work the linked issue puts out of scope.

🤖 Posted by Claude (an AI agent) on behalf of the user.

Comment on lines +135 to +138
// Fills the synthetic column, and any row whose mapped Unique ID cell is blank.
if (!row.at(externalIDColumnIndex)?.trim()) {
row[externalIDColumnIndex] = transactionID;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Report the number of transactions actually imported

When mapped IDs already exist during an exact or overlapping re-import, preserving them here lets the backend skip those rows, but every valid input row is still added to transactions and therefore included in transactionsCount. The success modal consequently says all input transactions “have been added” even when none, or only a subset, were inserted; use the backend's inserted count or avoid presenting the input-row count as the number added.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this is now inaccurate: before this PR dedup could never match, so every input row really was inserted and the count was right. With stable IDs a fully-deduped re-import will still report all rows as added.

Not fixing it here, for two reasons:

  1. The true inserted count only exists backend-side. The file is parsed asynchronously by the scraper well after ImportCSVCompanyCards returns, and this modal is built client-side from successData, so there is nothing accurate to substitute yet — it needs a backend count plumbed through.
  2. Rewording the modal so it does not claim a count (e.g. "Import started") is user-facing copy, which needs approval rather than a drive-by change in this PR.

Raised with the PR author to decide between softening the copy here or opening a follow-up for the backend count.

🤖 Posted by Claude (an AI agent) on behalf of the user.

A saved externalID index cannot be trusted to point at a real source column:
the import appends a synthetic externalID column when the user maps no Unique
ID, and that index is indistinguishable from a Unique ID mapped to the last
column. Treating it as an advanced field made basic feeds re-import in advanced
mode, and restoring the mapping could point Unique ID at an unrelated column of
the next file, whose repeated values would make the backend dedupe valid
transactions.

Also applies the translation corrections for es, ja and pt-BR.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@marufsharifi

marufsharifi commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@marufsharifi

Copy link
Copy Markdown
Contributor

@tgolen, could you please check this. it still seems to duplicate rows.

RF.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants