Utility Files for a Custom GL Lines Plug-In Implementation

You can create utility JavaScript files for use with a Custom GL Lines plug-in implementation. These utility files can contain the following types of logic:

Depending on your plug-in implementation requirements, you may want to not include internal NetSuite IDs in the implementation and utility script files. In this case, you can create a custom record type to store references to the internal IDs for NetSuite records, and then retrieve the IDs through SuiteScript. For an example, see Using a Custom Record to Reference Internal NetSuite IDs Example.

Helper Functions Example

You can use helper functions similar to the examples below to avoid using NetSuite internal IDs in the plug-in implementation logic.

Utility Javascript File

             // search for entity's email
   function findEntityEmail(entityId)
   {
      var searchFilters = new Array();
      searchFilters[0] = new nlobjSearchFilter('internalid', null, 'anyof', entityId);
      var searchColumns = new Array();
      searchColumns[0] = new nlobjSearchColumn('email');

      var searchResults = nlapiSearchRecord('entity', null, searchFilters, searchColumns);
      var email = '';
      if (searchResults!=null && searchResults.length > 0)
      {
         var email = searchResults[0].getValue('email');
      }
   return email;
   }

   // search for entity's phone with saved search
   function findEntityPhone(entityId)
   {
      var searchFilters = new Array();
      searchFilters[0] = new nlobjSearchFilter('internalid', null, 'anyof', entityId);
  
      var savedSearchResults = nlapiSearchRecord('entity', 'customsearch_script_id', searchFilters);
      var phone = '';
      if (savedSearchResults != null && savedSearchResults.length > 0)
      {
         phone = savedSearchResults[0].getValue('phone');
      }
   } 

        

Plug-in Implementation Script File

             function customizeGlImpact(transactionRecord, standardLines, customLines, book)
   {
      ...
      var entityId = transactionRecord.getFieldValue('entity');
      var email = findEntityEmail(entityId);
      var phone = findEntityPhone(entityId);
      ...
   } 

        

Internal NetSuite ID Example

The interface for the Custom GL plug-in includes methods that you can use to retrieve the internal NetSuite IDs for NetSuite records related to the transaction. You can use these IDs to define plug-in implementation functionality or with SuiteScript APIs like for example, nlapiLoadRecord(type, id, initializeValues) and nlapiSearchRecord(type, id, filters, columns). For more information, see SuiteScript 1.0 API Reference. However, these IDs are specific to a particular NetSuite account. You may want to include the account-specific IDs in a separate utility file so that they may be later customized if the plug-in implementation is installed in a different account.

The following example shows a helper function named getAccountIDforCustomLine(accountId) that returns the internal NetSuite ID for an account record. The account ID to return is included in the getAccountIDforCustomLine(accountId) function. The function is referenced in the main plug-in implementation script file.

Note:

This code is for demonstration purposes only. The customizeGlImpact(transactionRecord, standardLines, customLines, book) function does not add balanced custom lines and the transaction will not save.

Utility Javascript File

             // Utility methods
   function getAccountIDforCustomLine(accountId)
   {
      ...
      if (accountID == 30) // main transaction account is 4000 - Sales (id: 30)
      {
         return 40; // custom line account is 1000 - VAT Expenses (id:40)
      } else {
         // return something else
         ...
      }
   } 

        

Plug-in Implementation Script File

             function customizeGlImpact(transactionRecord, standardLines, customLines, book)
   {
      ...
      var newLine = customLines.addNewLine();
      newLine.setDebitAmount(amount);
      newLine.setAccountId(getAccountIDforCustomLine(standardLines.getLine(0).getAccountId()));
      newLine.setMemo("Payment catches both revenue and cash.");
      ...
   } 

        

Related Topics

Custom GL Lines Plug-in Example Code
Using a Custom Record to Reference Internal NetSuite IDs Example

General Notices