Deploy SuiteScripts and configure NetSuite workflows to trigger Field Nation work order creation.
NetSuite integration requires SuiteScript deployment to trigger webhooks:
Deploy User Event Script to trigger on record changes:
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define(['N/https', 'N/record'], (https, record) => {
const afterSubmit = (context) => {
try {
const newRecord = context.newRecord;
const status = newRecord.getValue({ fieldId: 'status' });
// Only trigger if status = "Ready for Dispatch"
if (status === 'Ready for Dispatch') {
const recordId = newRecord.id;
const recordType = newRecord.type;
// Field Nation trigger URL
const fnUrl = 'https://api.fieldnation.com/integrations/trigger/{YOUR_CLIENT_TOKEN}';
const payload = {
recordId: recordId,
recordType: recordType,
timestamp: new Date().toISOString()
};
const response = https.post({
url: fnUrl,
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json'
}
});
log.audit({
title: 'Field Nation Trigger Sent',
details: 'Record ID: ' + recordId + ', Response: ' + response.code
});
// Optional: Update custom field to track sync
// record.submitFields({
// type: recordType,
// id: recordId,
// values: { custbody_fn_synced: true }
// });
}
} catch (e) {
log.error({
title: 'Field Nation Trigger Error',
details: e.message
});
}
};
return {
afterSubmit: afterSubmit
};
});Save the script as fieldnation_trigger_ue.js
Customization → Scripting → Scripts → Files → SuiteScripts → Upload
Customization → Scripting → Scripts → New
Name: Field Nation Trigger
ID: customscript_fn_trigger
Script File: Select uploaded file
Function: afterSubmit
Applied To: Select record type (Service Order, Case, etc.) Status: Testing (initially) Execute As Role: Administrator Log Level: Debug (for testing)
Audience: All Roles
Click "Save"
Customization → Scripting → Script Execution Log
Look for "Field Nation Trigger Sent" log entry
Verify work order created with correct data
Check for any errors in execution log
Add complex logic to SuiteScript:
// Only trigger for specific subsidiaries
const subsidiary = newRecord.getValue({ fieldId: 'subsidiary' });
if (subsidiary !== 'US Operations') return;
// Only for high-priority orders
const priority = newRecord.getValue({ fieldId: 'priority' });
if (priority < 3) return;
// Check custom field
const sendToFN = newRecord.getValue({ fieldId: 'custbody_send_to_fn' });
if (!sendToFN) return;// Check if already synced
const fnSynced = newRecord.getValue({ fieldId: 'custbody_fn_synced' });
if (fnSynced) {
log.audit('Already synced', 'Skipping');
return;
}
// Send webhook...
// Mark as synced
record.submitFields({
type: newRecord.type,
id: newRecord.id,
values: { custbody_fn_synced: true },
options: { enableSourcing: false, ignoreMandatoryFields: true }
});Deploy and test in NetSuite sandbox account
Change deployment status to "Released"
Watch script execution logs for first week
Adjust conditions, improve performance, reduce API calls
Last updated on