Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Last active April 17, 2023 23:35
Show Gist options
  • Save iloveitaly/3ee0ddd124d10cd4fdc32c1df7fd871a to your computer and use it in GitHub Desktop.
Save iloveitaly/3ee0ddd124d10cd4fdc32c1df7fd871a to your computer and use it in GitHub Desktop.
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