Using a Custom Record to Reference Internal NetSuite IDs Example
You can use a custom record type to store the references to the required NetSuite standard records and retrieve them through SuiteScript. For more information about creating custom record types, see Creating Custom Record Types in the Customization documentation.
The following custom record example and plug-in implementation code is for demonstration purposes only. Your implementation may differ depending on your requirements. You can use a similar solution to retrieve other IDs, like subsidiaries or entities. Also, you use a similar method to create a solution that is not language-dependent.
To store and retrieve references to internal NetSuite IDs, complete the following steps:
-
Create a custom record type with an ID of customrecord_tutorial_account_config and add a field that references a standard NetSuite record. For example, create a custom record type named Account Configuration to store references to the accounts required by the plug-in implementation. Then, create a field for the custom record type with the following configuration:
Field Property
Value
Label
Account
ID
_account
Type
List/Record
List/Record
Account
-
Create a new instance of the custom record. For this example, you create a custom record with a name of Cash Basis Income Account that references a NetSuite account that you want to use with a custom line in the plug-in implementation.
-
Create the plug-in implementation and utility script files. The helper function
findConfiguredAccount(name)
searches for the account name and returns the internal NetSuite account ID.
Utility Javascript File
// Returns internal ID of account from a custom record with the name specified in parameter
function findConfiguredAccount(name)
{
var searchFilters = new Array();
searchFilters[0] = new nlobjSearchFilter('name', null, 'is', name);
searchFilters[1] = new nlobjSearchFilter('isinactive', null, 'is', 'F');
var searchColumns = new Array();
searchColumns[0] = new nlobjSearchColumn('custrecord_account');
var searchResults = nlapiSearchRecord('customrecord_tutorial_account_config', null, searchFilters, searchColumns);
if (searchResults!=null && searchResults.length > 0)
{
return searchResults[0].getValue('custrecord_account');
}
throw "Account " + name + " not found";
}
Plug-in Implementation Script File
function customizeGlImpact(transactionRecord, standardLines, customLines, book)
{
...
var accountId = findConfiguredAccount('Cash Basis Income Account');
line.setAccountId(accountId);
...
}