How to Distinguish a NetSuite Entity as a Customer vs. a Project

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.

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is Southern California's NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 25 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to setup a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - Google Plus - YouTube

| Tags: , , , | Category: NetSuite, Technical | 4 Comments

3 Comments

  1. Corey Hunt
    Posted February 12, 2016 at 8:32 am | Permalink

    Nice one Marty. I love the undocumented ones.

  2. Munzareen
    Posted June 20, 2016 at 9:38 pm | Permalink

    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.

  3. Posted June 26, 2016 at 8:30 pm | Permalink

    Hello Munzareen,

    Have you seen the courses offered by NetSuite?

    http://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

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>