How to Automate Customer Deposit Creation in NetSuite Using Custom Records and SuiteScript

by | Jun 28, 2024 | NetSuite Fundamentals | 0 comments

NetSuite users often face the challenge of importing customer deposits using the CSV import tool, as this option is not directly available. This blog post provides a detailed guide on creating a custom record in NetSuite to mimic the fields required on a customer deposit, using the import tool to create records from the custom record, and employing SuiteScript to generate customer deposits for each custom record. This approach streamlines the process, ensuring data accuracy and efficiency.

Step 1: Creating a Custom Record in NetSuite

To begin, create a custom record that mirrors the fields required on a customer deposit.

  1. Navigate to Custom Record Type:
    • Go to Customization > Lists, Records, & Fields > Record Types > New.
  2. Define the Custom Record:
    • Enter a name for the custom record (e.g., “SATW | Custom Customer Deposits”).
    • Set the ID (e.g., “customrecord_custom_customer_deposit”).
  3. Add Fields:
    • Add fields to the custom record to capture all necessary data for a customer deposit. Typical fields include:
      • Customer (List/Record: Customer)
      • Deposit Amount (Currency)
      • Deposit Date (Date)
      • Memo (Free-Form Text)
      • Payment Method (List/Record: Payment Method)
      • Reference Number (Free-Form Text)
      • Bank Account (List/Record: Account)
  4. Save the Custom Record Type.

Step 2: Using the Import Tool to Create Custom Records

With the custom record in place, the next step involves using the CSV import tool to create records from the custom record. More detailed steps about creating CSV imports can be found within a previous Suite Answers That Work post, Batch Update Transaction Item Fields Quickly with the NetSuite CSV under the subheading “Create The Import Map”.

For this import:

  • Import Type = Custom Records
  • Type = custom record name created in the previous step (e.g., “SATW | Custom Customer Deposits”).

Step 3: Creating a SuiteScript to Generate Customer Deposits

/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/search'], function(record, search) {

    function afterSubmit(context) {
        if (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) {
            return;
        }

        var customRecord = context.newRecord;

        var customerId = customRecord.getValue('custrecord_customer');
        var depositAmount = customRecord.getValue('custrecord_deposit_amount');
        var depositDate = customRecord.getValue('custrecord_deposit_date');
        var memo = customRecord.getValue('custrecord_memo');
        var paymentMethod = customRecord.getValue('custrecord_payment_method');
        var referenceNumber = customRecord.getValue('custrecord_reference_number');
        var bankAccount = customRecord.getValue('custrecord_bank_account');

        try {
            var customerDeposit = record.create({
                type: record.Type.CUSTOMER_DEPOSIT,
                isDynamic: true
            });

            customerDeposit.setValue({
                fieldId: 'customer',
                value: customerId
            });

            customerDeposit.setValue({
                fieldId: 'payment',
                value: depositAmount
            });

            customerDeposit.setValue({
                fieldId: 'trandate',
                value: depositDate
            });

            if (memo) {
                customerDeposit.setValue({
                    fieldId: 'memo',
                    value: memo
                });
            }

            if (paymentMethod) {
                customerDeposit.setValue({
                    fieldId: 'paymentmethod',
                    value: paymentMethod
                });
            }

            if (referenceNumber) {
                customerDeposit.setValue({
                    fieldId: 'tranid',
                    value: referenceNumber
                });
            }

            if (bankAccount) {
                customerDeposit.setValue({
                    fieldId: 'account',
                    value: bankAccount
                });
            }

            customerDeposit.save();
        } catch (e) {
            log.error('Error creating customer deposit', e.message);
        }
    }

    return {
        afterSubmit: afterSubmit
    };
});

The final step is to create a SuiteScript that generates customer deposits for each custom record, similar to the above example.

  1. Create a User Event Script:
    • Go to Customization > Scripting > Scripts > New > User Event Script.
  2. Write the SuiteScript:
    • Use the SuiteScript 2.0 example shown above as a guide to automate the creation of customer deposits. The specific field IDs will need to make the IDs of the target environment.
  3. Deploy the Script:
    • Go to Customization > Scripting > Script Deployments > New. Select the script file created and choose the custom record type (e.g., “SATW | Custom Customer Deposits”) as the Applies To.
    • Set the status to Released.

Step 4: Test Process End-to-End to Ensure Desired Result

Thoroughly test out new functionality before releasing it into a Production environment. While testing, the customer record’s permission level can also be set to restrict access.

Conclusion

Automating the creation of customer deposits in NetSuite using custom records and SuiteScript enhances efficiency and accuracy. Following the steps outlined in this guide, users can seamlessly import customer deposits from a CSV file and ensure that each custom record is converted into a customer deposit through SuiteScript automation. This method not only saves time but also minimizes the risk of data entry errors, providing a streamlined solution for managing customer deposits in NetSuite.

About Us

We are NetSuite Solutions Providers with 30+ years of combined experience.  We specialize in implementation, optimization, integration, rapid project recovery and rescue as well as custom development to meet any business need. Although every business is unique, with 40+ NetSuite clients over the last 5+ years our NetSuite Consultants have most likely seen your challenge or created a similar solution. If you would like more information on NetSuite or just have questions on your project, feel free to contact us Here.

Join our mailing list to stay up to date on the latest NetSuite solutions.