Friday, April 12, 2019

Get Customer ID and Customer Name in NetSuite 2013.2

Before NetSuite 2013.2 the field entityid has contained only Customer ID and field altname has contained 
firstname + lastname or companyname. In NetSuite 2013.2 the entityid keeps Customer Name and 
altname of customer is null.

Example: 
NetSuite 2013.1
Customer ID = entityid  = 1234
Customer Name = altname = Clowns & Jokers Ltd.

NetSuite 2013.2
Customer ID = entityid  = Clowns & Jokers Ltd.
Customer Name = altname = null
Internal ID = internalid = 1234

In accordance to WSDL for NetSuite 2013.2 should be changed the name of used fields. 
- is need to use entityid  instead of altname - get 'Clowns & Jokers Ltd.'
- is need to use internalid instead of entityid – get '1234'

Here is a short testing script to get the correct values. This script is working with saved search:

function CustomerNames ()
{
var CustID = nlapiGetFieldValue('entity'); // ID of customer from current SO
nlapiLogExecution ('DEBUG', 'CustID', CustID);

var filters = new Array();  // new array for filters of the search
filters[0] = new nlobjSearchFilter('internalid', null, 'anyof', CustID); 
// filter: internalid of customer equals to CustID


var columns = new Array();  // new array for columns of the search
columns[0] = new nlobjSearchColumn ('entityid'); 
columns[1] = new nlobjSearchColumn ('internalid'); 


var SavedSearch = nlapiSearchRecord('customer', null, filters, columns); 
// run the search on 'customer' record type


for (var i = 1 in SavedSearch) {  // run through the results in a cycle
var SearchResult = SavedSearch[i];


var Cextid = SearchResult.getValue(columns[0]); // get the name of customer
nlapiLogExecution ('DEBUG', 'Cextid', Cextid);


var Caltname = SearchResult.getValue(columns[1]); // get the ID of customer
nlapiLogExecution ('DEBUG', 'Caltname', Caltname);
}
}

No comments:

Post a Comment