Introduction: NetSuite User Event scripts are powerful tools for automating processes within your NetSuite environment. Sometimes, there’s a need to pass values between different phases of a User Event script, such as from BeforeSubmit to AfterSubmit. This article explores a technique using the Cache module to achieve this seamless data transfer.
Using the Cache Module: The Cache module in NetSuite provides a way to store and retrieve data that can be shared across different executions and contexts of scripts. This becomes particularly useful when you want to pass data from the BeforeSubmit phase to the AfterSubmit phase of a User Event script.
Here’s a sample implementation using the Cache module:
// Create a cache instance with a private scope
var myCache = cache.getCache({
name: 'temporaryCache',
scope: cache.Scope.PRIVATE
});
// Pass data from BeforeSubmit to Cache
var usedCMIDs = ['123', '456', '789'];
myCache.put({
key: 'usedCMIDs',
value: JSON.stringify(usedCMIDs),
ttl: 18000 // Time-to-live in seconds
});
// In the AfterSubmit phase, retrieve data from Cache
var usedCMIDsFromCache = JSON.parse(myCache.get({
key: 'usedCMIDs',
ttl: 18000
}));
// Now, 'usedCMIDsFromCache' contains the values passed from BeforeSubmit