This article is relevant if you are a SuiteScript developer and you are working on a solution that needs to distinguish customers vs. project entities.
Background
In some recent work on our Distinguish NetSuite Sales as “New” vs. “Existing” solution, we needed some intelligence to distinguish between entities that are customers vs. projects. This is easy to do if you have NetSuite’s SRP (Advanced Projects) module active because transaction records have two fields that are consistently applied: Customer (entity) and Project (job). However, if you are not using NetSuite’s SRP (Advanced Projects) module, and you want to use Projects to distinguish records, you only have one transaction entity field. That entity can either be a Customer type or a Project type record.
We also wanted to know what the top level parent was for any sub structure. NetSuite is sophisticated because it can express a hierarchy of customers and projects. After some interrogation of the object model, we discovered some undocumented fields that can help in this endeavor.
SuiteScript Code Pattern to Determine Projects and Customers
The following code pattern was developed by one of our engineers after a session where she and I wanted to get a central function to help in our transaction work.
Customer/Project AfterSubmit Event
var entity = nlapiGetNewRecord(); var type = entity.getRecordType(); var parent = entity.getId(); if(type == ‘job’){ parent = entity.getFieldValue(‘kcustomer’); //undocumented }; var s = nlapiSearchRecord('customer',null, new nlobjSearchFilter('internalid',null,'anyof',parent), new nlobjSearchColumn('internalid','toplevelparent') ); if(s){ var toplevelparent = s[0].getValue('internalid','toplevelparent'); };
Transaction AfterSubmit Event
//check entity record type //leverage if the environment has NetSuite SRP (Advanced Projects) activated var record = nlapiGetNewRecord(); var isadvance = nlapiGetContext().getFeature('ADVANCEDJOBS'); var entity = record.getFieldValue(‘entity’); var recordtype = record.getRecordType(); var parent = entity; if(!isadvance){ recordtype = nlapiLookupField('customer',entity,'stage'); if(recordtype == ‘JOB’){ parent = nlapiLoadRecord(recordtype, entity).getFieldValue(‘kcustomer’); //undocumented }; };
Grow your NetSuite Expertise
If you are a NetSuite programmer and you want to be appreciated for your capacity to produce innovations on the platform, perhaps we can work together. Our standards for quality are high and we care about ethics. Reach out to me and let’s talk about your ambitions.
Nice one Marty. I love the undocumented ones.
I m new on suitescript. I don’t know how to create our custom portal using netsuite and also don’t know the architecture of netsuite. Can anyone help me please.
Hello Munzareen,
Have you seen the courses offered by NetSuite?
https://www.netsuite.com/portal/services/training.shtml
Also, NetSuite’s built-in Help document is pretty good. Generally though, we help our clients to solve platform challenges via a professional services relationship.
Marty