ANS-1563 · SUITESCRIPT DEVELOPMENT

How to Set a NetSuite Coupon Code on a Transaction Using SuiteScript?

Distinguish between promotion and coupon code internal IDs for accurate programmatic discount application.

Short answer

When setting a coupon code on a NetSuite transaction via script, use record.setFieldValue('couponcode', internalidofcouponcode). It is critical to use the internal ID of the specific coupon code, not the promotion record's internal ID, as these are distinct. Coupon code records are accessible within the NetSuite UI.

Scenario

Users attempting to apply a promotion code to a NetSuite transaction using server-side SuiteScript, such as a Suitelet, may encounter issues where the promotion does not apply correctly. This often stems from an incorrect understanding or usage of the distinct internal IDs for promotions versus individual coupon codes.

Solution

The primary issue when programmatically setting coupon codes is often the confusion between the internal IDs of the main promotion record and the specific coupon code record. These two entities are distinct in NetSuite. While promotion records define the overall discount rules, individual coupon codes are associated with them and are used for application on transactions.Coupon code records are accessible and manageable within the NetSuite UI, particularly on the 'Coupons' or 'Codes' subtab of a Promotion record.To correctly apply a coupon code to a transaction via SuiteScript, ensure that the script uses the couponcode field and provides the internal ID of the specific coupon code, not the internal ID of the promotion record.Use the following SuiteScript method:

record.setFieldValue('couponcode',internalidofcouponcode)

Verify that internalidofcouponcode refers to the actual internal ID of the coupon code record.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant