Skip to content

[$250] Netsuite - Sync fails after adding a custom segment/record #86357

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: v9.3.44-0
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #80996
Email or phone of affected tester (no customers): n/a
Issue reported by: Applause Internal Team
Bug source: Exploratory - Critical User Impact
Device used: MacBook Air 15.2.1
App Component: Workspace Settings

Action Performed:

Prerequisite: accounting feature is enabled and Netsuite is connected on the workspace

  1. Go to https://staging.new.expensify.com
  2. Go to the workspace > Accounting > Import > Custom segments/records > Add custom segment/record
  3. Finish the flow and click Confirm

Expected Result:

After adding a custom segment/record the Netsuite connecting should synchronize successfully.

Actual Result:

Netsuite synchronization fails after adding a custom segment/record.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

Bug7113086_1774458496598.Recording__1887.mp4

View all open jobs on GitHub

Issue OwnerCurrent Issue Owner: @youssef-lr
Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~022036899455912557492
  • Upwork Job ID: 2036899455912557492
  • Last Price Increase: 2026-05-20

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on Mar 25, 2026
  2. MelvinBot commented on Mar 25, 2026

    @MelvinBot
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user adds a custom segment/record in Workspace > Accounting > Import > Custom segments/records > Add custom segment/record, the NetSuite synchronization fails after completing the flow and clicking Confirm.

    What is the root cause of that problem?

    Based on investigation of the App-side code, the custom segment addition flow works as follows:

    1. User selects the segment type (customSegment vs customRecord) in Step 0 (ChooseSegmentTypeStep)
    2. User fills in segmentName, internalID, scriptID, and mapping in subsequent steps
    3. On Confirm, handleFinishStep at NetSuiteImportAddCustomSegmentContent.tsx:56-78 constructs the new segment object and calls updateNetSuiteCustomSegments
    4. updateNetSuiteCustomSegments at NetSuiteCommands.ts:597-618 sends API.write('UpdateNetSuiteCustomSegments', {policyID, customSegments: JSON.stringify(records)}) to the backend

    The segmentType (whether it's a customSegment or customRecord) is not included in the API payload. The NetSuiteCustomSegment type only has 4 fields: segmentName, internalID, scriptID, mapping. The segment type is stored in the form draft and used for UI display but is never sent to the backend.

    The frontend correctly sends the data as defined by the type system. The frontend does not trigger a sync — only API.write('UpdateNetSuiteCustomSegments') is called. The backend likely triggers the NetSuite sync automatically after processing this write command. Since this bug is reproducible in production (not just staging), the sync failure likely originates on the server side when the backend tries to configure the custom segment/record in NetSuite without knowing whether it's a segment or record.

    Note: This is a pre-existing issue — the segmentType field has never been part of the NetSuiteCustomSegment type. This was not introduced by the recent useSubPage refactor PR, which only changed the navigation model (from useSubStep to useSubPage) without modifying the data submission logic.

    What changes do you think we should make in order to solve the problem?

    This requires investigation on the server side to determine:

    1. Does the UpdateNetSuiteCustomSegments backend handler need the segment type? If so, the fix would involve:

      • Adding segmentType to the NetSuiteCustomSegment type in src/types/onyx/Policy.ts
      • Including segmentType in the segment object built in handleFinishStep at NetSuiteImportAddCustomSegmentContent.tsx:59-65
      • The API parameters would automatically pick it up since the full array is JSON-stringified
    2. Is the sync failure caused by something else on the backend? — Server logs for the UpdateNetSuiteCustomSegments command should be checked to see the exact error during the sync attempt.

    What alternative solutions did you explore? (Optional)

    I also investigated whether the useSubPage refactor in PR #80996 could cause timing issues (stale closures, premature navigation). While the refactor changed the navigation paradigm from in-memory state to URL-based routing, the core handleFinishStep function and its data construction are unchanged and function correctly. The fact that this bug reproduces in production (which wouldn't have the refactor yet) confirms the refactor is not the cause.

    Additionally, I found a secondary bug: the edit form validation in NetSuiteImportCustomFieldEdit.tsx:107-113 always checks uniqueness against customSegments even when editing a customList — but this is a separate issue and wouldn't cause sync failures.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  3. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on Mar 25, 2026
  4. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Mar 25, 2026
  5. melvin-bot commented on Mar 25, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)

  6. changed the title [-]Netsuite - Sync fails after adding a custom segment/record[/-] [+][$250] Netsuite - Sync fails after adding a custom segment/record[/+] on Mar 25, 2026
  7. melvin-bot commented on Mar 25, 2026

    @melvin-bot
  8. trasnake87 commented on Mar 26, 2026

    @trasnake87
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    When a user adds a custom segment or custom record via Workspace > Accounting > NetSuite > Import > Custom segments/records, the subsequent NetSuite synchronization fails.

    What is the root cause of that problem?

    The segmentType field (which distinguishes a customSegment from a customRecord) is collected from the user in step 0 of the flow but is never included in the segment object sent to the backend. In NetSuiteImportAddCustomSegmentContent.tsx#L59-L65, the object constructed for the API call only includes segmentName, internalID, scriptID, and mapping — omitting segmentType. The NetSuiteCustomSegment type also lacks this field entirely. Without knowing whether the entry is a custom segment or custom record, the backend cannot issue the correct NetSuite API calls during sync.

    What changes do you think we should make in order to solve the problem?

    1. Add segmentType to the NetSuiteCustomSegment type in src/types/onyx/Policy.ts:
    type NetSuiteCustomSegment = {
        segmentName: string;
        internalID: string;
        scriptID: string;
        mapping: NetSuiteCustomFieldMapping;
        /** Whether this is a custom segment or custom record */
        segmentType: string;
    };
    1. Include segmentType in the object built in handleFinishStep in NetSuiteImportAddCustomSegmentContent.tsx:
    const updatedCustomSegments = customSegments.concat([
        {
            segmentName: values[INPUT_IDS.SEGMENT_NAME],
            internalID: values[INPUT_IDS.INTERNAL_ID],
            scriptID: values[INPUT_IDS.SCRIPT_ID],
            mapping: values[INPUT_IDS.MAPPING] ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG,
            segmentType: values[INPUT_IDS.SEGMENT_TYPE],
        },
    ]);

    No other changes needed — the value is already JSON-stringified before being sent via API.write, so the backend will automatically receive the new field.

    What alternative solutions did you explore? (Optional)

    We considered whether the backend could infer the segment type from the scriptID format, but this would be fragile and the data is already available on the frontend — it simply is not being forwarded.

  9. trasnake87 commented on Mar 26, 2026

    @trasnake87
    Contributor

    Contributor details
    Your Expensify account email: trasnake87@gmail.com
    Upwork Profile Link: https://www.upwork.com/freelancers/~010f770315ab181656

  10. melvin-bot commented on Mar 26, 2026

    @melvin-bot

    ✅ Contributor details stored successfully. Thank you for contributing to Expensify!

  11. BarryArinze commented on Mar 26, 2026

    @BarryArinze

    Proposal

    ### 1) Please re-state the problem that we are trying to solve in this issue.

    When a user adds a custom segment or custom record via Workspace > Accounting > NetSuite > Import > Custom segments/records, the subsequent NetSuite synchronization fails.

    ### 2) What is the root cause of that problem?
    I identified several potential root causes:

    • Missing Sync Stage for Custom Segments: In the CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME constants, there are sync stages for NETSUITE_SYNC_IMPORT_CUSTOM_LISTS but no corresponding sync stage for custom segments. The custom segments addition triggers the updateNetSuiteCustomSegments function but there's no dedicated sync stage to handle the synchronization process.

    • Incomplete Sync Progress Tracking: The updateNetSuiteCustomSegments function in NetSuiteCommands.ts updates the configuration but doesn't initiate a proper sync progress state using POLICY_CONNECTION_SYNC_PROGRESS like other NetSuite operations do.

    • Missing Sync Trigger: After adding custom segments via NetSuiteImportAddCustomSegmentContent.tsx, the code only updates the configuration but doesn't trigger the actual synchronization process that would validate the connection and sync the new custom segment data.

    ### 3) What changes do you think we should make in order to solve the problem?

    1. Add Custom Segment Sync Stage: Add a new sync stage constant in CONST/index.ts:

    typescript

    NETSUITE_SYNC_IMPORT_CUSTOM_SEGMENTS: 'netSuiteSyncImportCustomSegments',
    1. Modify updateNetSuiteCustomSegments Function: Update the function in NetSuiteCommands.ts to initiate sync progress tracking similar to other NetSuite operations:
    function updateNetSuiteCustomSegments(
        policyID: string | undefined,
        records: NetSuiteCustomSegment[],
        oldRecords: NetSuiteCustomSegment[],
        modifiedSegmentID: string,
        pendingAction: OnyxCommon.PendingAction,
    ) {
        if (!policyID) {
            return;
        }
    
        // Add sync progress tracking
        const optimisticData = [
            {
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`,
                value: {
                    stageInProgress: CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.NETSUITE_SYNC_IMPORT_CUSTOM_SEGMENTS,
                    connectionName: CONST.POLICY.CONNECTIONS.NAME.NETSUITE,
                    timestamp: new Date().toISOString(),
                },
            },
        ];
    
        const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_SEGMENTS, records, oldRecords, modifiedSegmentID, pendingAction);
        
        // Merge the sync progress with existing optimistic data
        onyxData.optimisticData = [...optimisticData, ...onyxData.optimisticData];
    
        API.write(
            WRITE_COMMANDS.UPDATE_NETSUITE_CUSTOM_SEGMENTS,
            {
                policyID,
                customSegments: JSON.stringify(records),
            },
            onyxData,
        );
    }
    1. Add Backend Sync Logic: Ensure the backend handles the new NETSUITE_SYNC_IMPORT_CUSTOM_SEGMENTS stage to properly synchronize custom segment data with NetSuite.

    2. Add Validation in Custom Segment Flow: In NetSuiteImportAddCustomSegmentContent.tsx, add validation to ensure the NetSuite connection is still valid before attempting to add custom segments.

    3. Improve Error Handling: Add better error handling and user feedback when sync fails after custom segment addition.

    ### 4) What alternative solutions did you explore? (Optional)

    1. Manual Sync Trigger: Consider adding a "Sync Now" button after custom segment addition to manually trigger synchronization, but this would be a poor user experience compared to automatic sync.

    2. Batch Processing: Instead of immediate sync, queue the custom segment changes and process them during the next regular sync cycle, but this could cause data inconsistency issues.

    3. Separate Sync Process: Create a completely separate sync process for custom segments independent of the main NetSuite sync, but this would add complexity and potential race conditions.

  12. BarryArinze commented on Mar 26, 2026

    @BarryArinze

    🚫 Duplicated proposal withdrawn by 🤖 ProposalPolice.

  13. 82 remaining items

  14. melvin-bot commented on Jul 21, 2026

    @melvin-bot

    @youssef-lr Huh... This is 4 days overdue. Who can take care of this?

  15. youssef-lr commented on Jul 22, 2026

    @youssef-lr
    Contributor

    No update from customer yet.

  16. melvin-bot commented on Jul 28, 2026

    @melvin-bot

    @youssef-lr Eep! 4 days overdue now. Issues have feelings too...

  17. youssef-lr commented on Jul 29, 2026

    @youssef-lr
    Contributor

    No update

  18. melvin-bot commented on Aug 4, 2026

    @melvin-bot

    @youssef-lr Eep! 4 days overdue now. Issues have feelings too...

  19. youssef-lr commented on Aug 5, 2026

    @youssef-lr
    Contributor

    Going to close this for now until. It looks like this was user error when entering the wrong ID.

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

Metadata

Metadata

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributors

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions