Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Normalize a NetSuite entity ID to a valid customer internal ID reference using SuiteScript
// Author <mike@suitesync.io>
// ensure that an entity ID is actually a customer ID
// http://blog.prolecto.com/2016/02/12/how-to-distinguish-a-netsuite-entity-as-a-customer-vs-a-project/
function retrieveCustomerId(entityId) {
var isAdvancedJobs = nlapiGetContext().getFeature('ADVANCEDJOBS');
var customerId = entityId;
if(!isAdvancedJobs) {
entityType = nlapiLookupField('customer', entityId, 'stage');
if(entityType == 'JOB'){
// undocumented `kcustomer`
customerId = nlapiLoadRecord(entityType, entityId).getFieldValue('kcustomer');
}
}
return customerId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment