Loading Multiple Types of Transaction Records Without The Specific Type

in , , March 29th, 2024
woman in black shirt sitting beside black flat screen computer monitor

When you're working with SuiteScript, you may run into situations where you are running a transaction search for records and need to load those records, but don't know the type of each specific record. The set of code blocks included below are useful if you are processing multiple types of transactions, and you need the specific record.Type for each type of transaction that you are working on.

Load NetSuite Transaction Records Step-by-Step

  1. Get a list of all the specific types of transactions your script will be processing.
  2. Create a transaction mapping object, mapping the internal NetSuite transaction type code to the correct record.Type value.

Below is an example:

        const TRANSACTION_MAPPING = {
            "VendBill": record.Type.VENDOR_BILL,
            "ItemRcpt": record.Type.ITEM_RECEIPT,
            "Journal": record.Type.JOURNAL_ENTRY,
            "CashSale": record.Type.CASH_SALE,
            "CashRfnd": record.Type.CASH_REFUND,
            "CustInvc": record.Type.INVOICE,
            "InvAdjst": record.Type.INVENTORY_ADJUSTMENT,
            "Check": record.Type.CHECK
        };

3. Add the record type as a search column, as such below:

search.createColumn({name: "type", label: "Type"})

4. When loading each record, use result.getValue(“type”) with your transaction mapping to get the correct record.Type loaded.

This is how it would look:

const transactionRecord = record.load({
    type: TRANSACTION_MAPPING[result.getValue("type")],
    id: result.getValue("internalid")
});

Author: John Baylon 


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart