Last active
April 17, 2023 23:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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