Repository navigation
Description
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:
- User selects the segment type (
customSegmentvscustomRecord) in Step 0 (ChooseSegmentTypeStep)- User fills in
segmentName,internalID,scriptID, andmappingin subsequent steps- On Confirm,
handleFinishStepatNetSuiteImportAddCustomSegmentContent.tsx:56-78constructs the new segment object and callsupdateNetSuiteCustomSegmentsupdateNetSuiteCustomSegmentsatNetSuiteCommands.ts:597-618sendsAPI.write('UpdateNetSuiteCustomSegments', {policyID, customSegments: JSON.stringify(records)})to the backendThe
segmentType(whether it's acustomSegmentorcustomRecord) is not included in the API payload. TheNetSuiteCustomSegmenttype 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
segmentTypefield has never been part of theNetSuiteCustomSegmenttype. This was not introduced by the recent useSubPage refactor PR, which only changed the navigation model (fromuseSubSteptouseSubPage) 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:
Does the
UpdateNetSuiteCustomSegmentsbackend handler need the segment type? If so, the fix would involve:
- Adding
segmentTypeto theNetSuiteCustomSegmenttype insrc/types/onyx/Policy.ts- Including
segmentTypein the segment object built inhandleFinishStepatNetSuiteImportAddCustomSegmentContent.tsx:59-65- The API parameters would automatically pick it up since the full array is JSON-stringified
Is the sync failure caused by something else on the backend? — Server logs for the
UpdateNetSuiteCustomSegmentscommand should be checked to see the exact error during the sync attempt.What alternative solutions did you explore? (Optional)
I also investigated whether the
useSubPagerefactor 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 corehandleFinishStepfunction 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-113always checks uniqueness againstcustomSegmentseven when editing acustomList— but this is a separate issue and wouldn't cause sync failures.
Next Steps for Contributor+ team: Reply with
@MelvinBot implement thisto create a draft PR,@MelvinBot <your feedback>to refine this analysis, or explain why you are rejecting Melvin's proposal.
Originally posted by @MelvinBot in #86357
Activity
melvin-bot commentedon Mar 26, 2026
📣 @BarryArinze! 📣
Please report bugs or suggest features in the #expensify-open-source Slack channel, don't directly open issues in this repo!
Instructions here to join the channel 📖