Introduction
NetSuite’s Map/Reduce framework is essential for processing high-volume transactions asynchronously. This article explores a technical deep dive into how fulfillment statuses are synchronized with external dispatch tracking systems using SuiteScript.
System Architecture Overview
The process involves:
- Data Extraction from NetSuite -> Identify unfinished item fulfillment transactions.
- External API Query -> Fetch real-time status updates from Dispatch Tracker.
- Bulk Status Updates in NetSuite -> Apply data transformations & update fulfillment records.
Step 1: Fetching Unfinished Orders Efficiently
Before processing fulfillment updates, the script queries NetSuite using indexed searches to optimize execution time.
const getUnfinishedDtOrders = () => {
try {
let searchQuery = search.create({
type: search.Type.ITEM_FULFILLMENT,
filters: [
[“type”, “anyof”, “ItemShip”],
“AND”, [“mainline”, “is”, “T”],
“AND”, [“createdfrom.type”, “anyof”, “SalesOrd”],
“AND”, [“custbody_sent_2_dt”, “isnotempty”, “”],
“AND”, [“custbody_jj_dt_fulfill_status”, “noneof”, [“Finished”, “Canceled”]],
“AND”, [“custbody_jj_dt_order_link”, “isnotempty”, “”]
],
columns: [
search.createColumn({ name: “internalid” }),
search.createColumn({ name: “tranid” }),
search.createColumn({ name: “entity” }),
search.createColumn({ name: “custbody_jj_dt_account” })
]
});
let results = [];
searchQuery.run().each(result => {
results.push({
internalId: result.getValue({ name: “internalid” }),
tranId: result.getValue({ name: “tranid” }),
entity: result.getValue({ name: “entity” }),
dtAccount: result.getValue({ name: “custbody_jj_dt_account” })
});
return true; // Continue iteration
});
return results;
} catch (error) {
log.error(“Error in getUnfinishedDtOrders”, error);
return [];
}
};
Step 2: Fetching Order Status from Dispatch Tracker
Once unfinished orders are identified, we check their status in Dispatch Tracker via API.
const getOrderStatusFromDispatchTracker = (tranId) => {
try {
let response = jjConfig.getOrderDetails(tranId);
if (response.status === 200 && response.service_orders.length > 0) {
return response.service_orders[0].status;
} else {
return null; // Handle missing or invalid data
}
} catch (error) {
log.error(“Error in getOrderStatusFromDispatchTracker”, error);
return null;
}
};
Step 3: Updating NetSuite Fulfillment Status
Once Dispatch Tracker confirms an order is Finished, NetSuite should reflect the update. Here’s the optimized record update logic:
const updateFulfillmentStatus = (recId) => {
try {
submitFields(record.Type.ITEM_FULFILLMENT, recId, {
custbody_jj_dt_fulfill_status: “Finished”,
shipstatus: “C”,
custbody_jj_dt_sync_error: ” “
});
} catch (error) {
log.error(“Error in updateFulfillmentStatus”, error);
}
};
Key Optimization Strategies
- Indexed searches improve retrieval performance.
- Batch processing using Map/Reduce ensures scalability.
- Robust API error handling prevents failures from affecting transactions.
This implementation enables seamless fulfillment status updates, ensuring inventory records align with Dispatch Tracker data.