ANS-0878 · SUITESCRIPT DEVELOPMENT

How to Apply a Gift Certificate to a Sales Order in NetSuite SuiteScript

Automate the application of gift certificates to sales orders using SuiteScript to streamline order processing.

Short answer

To apply a gift certificate to a sales order in SuiteScript, utilize functions like record.setSublistValue or record.setCurrentSublistValue to populate the gift certificate redemption sublist. This involves setting the authorization code and the amount to be applied, ensuring proper integration with sales order processing workflows.

Scenario

Organizations often need to programmatically apply gift certificates to sales orders within NetSuite. This automation is crucial for streamlining order fulfillment processes and ensuring accurate financial transactions when customers use gift certificates as a form of payment. Manually applying these can be time-consuming and prone to errors, necessitating a SuiteScript solution.

Solution

To programmatically apply a gift certificate to a sales order, SuiteScript 2.x functions such as record.setSublistValue or record.setCurrentSublistValue should be used. The specific internal IDs for the gift certificate redemption sublist and its fields (e.g., for authorization code and applied amount) should be verified in the NetSuite Records Browser for the current account version. A common approach involves setting the authorization code and the amount to be applied on the relevant sublist line.

An example of how this might be implemented, assuming the correct internal IDs and a record in dynamic or standard mode, is as follows:

javascript
// Assuming 'salesOrderRecord' is a loaded or created record object
// and 'giftCertInternalId', 'giftCertAmount' are defined variables.

// IMPORTANT: The sublist ID 'giftcertredemption' and field IDs 'authcode', 'authcodeapplied'
// are examples from SuiteScript 1.0 and require verification in the NetSuite Records Browser
// for SuiteScript 2.x to ensure correct functionality in your specific environment.
// Sublist lines are typically 0-indexed in SuiteScript 2.x.

salesOrderRecord.setSublistValue({
    sublistId: 'sublist_id_for_gift_certificate_redemption', // e.g., 'giftcertredemption'
    fieldId: 'field_id_for_authorization_code', // e.g., 'authcode'
    line: 0, // Adjust line index as needed; 0 for the first line
    value: giftCertInternalId
});

salesOrderRecord.setSublistValue({
    sublistId: 'sublist_id_for_gift_certificate_redemption', // e.g., 'giftcertredemption'
    fieldId: 'field_id_for_applied_amount', // e.g., 'authcodeapplied'
    line: 0, // Adjust line index as needed; 0 for the first line
    value: giftCertAmount
});

This approach ensures that the gift certificate's authorization code and the amount to be applied are correctly associated with the sales order.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant