Chain a NetSuite SuiteQL CSV export into Map/Reduce

Attach a Map/Reduce dependency to a SuiteQL CSV export, distinguish export completion from consumer completion, and reconcile the file with its processed rows.

The quick answer

Create the Map/Reduce task, pass it to the SuiteQL producer's addInboundDependency, then submit the producer. After successful export completion, the dependent becomes eligible for processing; queue and deployment availability can delay execution. Keep the producer's completion separate from the consumer's result; a completed export can still have a waiting or failed consumer.

The illustrated example executes JavaScript in local API adapters against six synthetic records. It writes a real CSV, runs the consumer and projects the computed file and log records into local NetSuite-style pages. The terminal commands and WAITING_EXPORT / RELEASED labels belong to that teaching model. Account task execution, native queue timing and external geocoding are outside this demonstration.

Before you start

In an account implementation, prepare an existing File Cabinet CSV target, the SuiteQL query, the consumer script and its declared input-path parameter. The dependent deployment must be deployed, available and Not Scheduled. Check the submitting role's query, script and file access before running it.

Set exactly one producer destination: fileId or filePath. The target CSV must already exist; creating a folder does not create the required file. This example uses Exports/customer_worklist.csv. Use script IDs, deployment IDs, custom fields and paths from your own account when adapting the code.

01 · Check the target and deployment

Find customer_worklist.csv in the local File Cabinet. Its initial size is 0 B, and the observed local file ID is 910. Existing bytes, including stale content, do not establish that a new export has completed.

Begin with an existing CSV target. This local file starts at 0 B.

Open Worklist Consumer. Confirm Deployed, Not Scheduled and the intended log level. On Parameters, verify Input CSV Path = Exports/customer_worklist.csv. Its internal parameter ID is custscript_worklist_path. Confirm that this parameter exists on the consumer script record, accepts the expected path text and is available to the deployment. Parameter creation is outside the illustrated steps. The producer supplies the same ID through params, and the consumer reads it with runtime.getCurrentScript().getParameter(). The consumer exports getInputData, map and summarize; this example has no reduce entry point.

The prepared dependent deployment and input parameter refer to the intended target.

02 · Attach the dependent task

Inspect export_worklist.js. It creates a Map/Reduce task for customscript_worklist_consumer, selects customdeploy_worklist_consumer and supplies the input-path parameter. The SuiteQL producer selects active synthetic customers with a null custom latitude and an address line.

Create the child, attach it with addInboundDependency, then submit the SuiteQL producer.

The orchestration calls are:

producer.addInboundDependency(child);
const taskId = producer.submit();

Submit the producer once. Do not independently submit the same child as a second processing path. Omit deploymentId only when automatic selection is intentional and an eligible deployment is available; otherwise specify it explicitly.

In the local workspace, type model submit. It returns suiteql-export-001, with producer PENDING. Child reads, releases and processed rows remain 0. This returned task ID is a submission receipt; it does not certify the destination's contents.

03 · Verify the completion boundary

Type model advance, then model inspect. The producer becomes PROCESSING. The adapter keeps the dependency at WAITING_EXPORT, with 0 child file reads, 0 releases and a 0 B target. It has not invoked the consumer's getInputData.

The local completion gate prevents a read while the export is unfinished.

Type model advance again. The producer becomes COMPLETE and writes 164 B, containing 3 data rows and 3 columns. The adapter releases the child once, while reads and processed rows remain 0. Compare the displayed SHA-256 with the artifact used for downstream processing.

Export completion releases the local dependent once. Consumer reads remain zero.

These manual commands advance a deterministic local test. Native scheduling can introduce a delay after dependency completion. WAITING_EXPORT and RELEASED are local labels, not native TaskStatus values.

04 · Process the completed CSV

Inspect read_worklist.js and csv_parser.js. The consumer loads the configured path, validates the id,entityid,address header and returns parsed objects from getInputData for the map stage. The custom parser handles the CSV; NetSuite is not being asked to infer arbitrary CSV columns. Splitting text at every comma or physical newline would break these addresses.

Type model run-consumer. The consumer reads once and processes 8401, 8402 and 8406. The query excluded the other three synthetic inputs. The release count stays 1, and the completion message reads Processed 3 customer rows.

In this local replay, a separate consumer execution processes three generated CSV records.

The first address contains a comma, quoted text and a newline: North Yard, Dock "B", followed by Bay 4. The second contains East Depot, followed by Receiving. Each remains one address field. The output shows escaped characters through JSON logging; no address is sent to a provider.

05 · Reconcile the file and log

Return to the local File Cabinet. The same path/name now shows observed local ID 910 and 164 B. Download the CSV and compare its bytes and hash with the completed artifact. This adapter retains its file ID; observe the actual post-export identity in an account rather than assuming overwrite behavior.

Reconcile the observed file identity and size, then verify the downloaded bytes.

Open the local Worklist Consumer > Execution Log projection with Type = - All -. Check the three Read customer entries and Worklist complete. Their customer IDs, address values and count must agree with the completed CSV.

The local generated file, parser output and execution-log projection agree on three records.

The file and log reconcile this local execution. The three rows are data records excluding the header; the three columns are parsed CSV fields. The hash identifies this local artifact, whose encoding and byte layout are not a guarantee about native exports.

When adapting the pattern, retain the producer task ID and check it later with task.checkStatus; submitting it does not synchronously wait for completion. Verify the dependent Map/Reduce execution separately, then inspect the resulting file and consumer output. These native status checks are account verification steps beyond the local replay.

Handle failed exports and unavailable deployments explicitly. A failed producer does not certify any existing destination bytes. Prevent overlapping runs from sharing a target or dependent deployment unintentionally, and report dependency-submission errors before retrying. Use a controlled destination or run identifier to distinguish the current artifact from stale content.

Common questions

Which task receives addInboundDependency?

Call it on the SuiteQL producer and pass the configured, unsubmitted dependent Map/Reduce task. Then submit the producer. The dependent must be a supported scheduled-script or Map/Reduce task with an available deployment.

Should I submit the dependent task separately?

Use the producer's dependency mechanism for this handoff. Submitting the same consumer independently creates another processing path and can cause it to read the destination before the intended export is ready.

Can filePath point to a new CSV that does not exist?

The SuiteQL task requires an existing target CSV that the submitting role can access. Prepare the file first and supply filePath or fileId, not both. The path must identify the file rather than only its folder.

Does producer COMPLETE mean the Map/Reduce succeeded?

Producer completion establishes the export outcome. The dependent may still be waiting, running or failed. Check its execution result and reconcile its processed rows with the completed file.

Why must the dependent deployment be Not Scheduled?

A dependent Map/Reduce deployment must be deployed and available with status Not Scheduled. A scheduled deployment is not the deployment configuration required for this task dependency. Availability and permissions still apply.

Why avoid splitting CSV on commas and newlines?

Quoted fields can contain both. A CSV parser preserves those characters within one field and handles doubled quotes. This example keeps multiline addresses intact and logs their JSON representation for verification.

Are WAITING_EXPORT and RELEASED NetSuite task statuses?

They are labels in this local adapter. They make the completion boundary visible without claiming to reproduce native queue timing or the platform's full task-status model.

Does this demonstration export real customer addresses or call Google?

It queries six synthetic local records and processes the resulting local CSV. It performs no account customer export, geocoding request or provider authentication.