What is the best method of passing values from BeforeSubmit to AfterSubmit portion of a User Event Script.


My objective is to pass values from the BeforeSubmit and use it in the AfterSubmit portion of a User Event Script.

After reading some doc, I found the Cache module was a viable option. But is it the best method?

Context of full script below: automate the following workaround https://netsuite.custhelp.com/app/answers/detail/a_id/23967/kw/cash%20sale%20credit%20memo to apply a Credit Memo to a Cash Sale  before Credit Card gateway process.


var myCache = cache.getCache({

name: 'temporaryCache',

scope: cache.Scope.PRIVATE


key: 'usedCMIDs',

value: JSON.stringify(usedCMIDs),

ttl: 18000

var usedCMIDs = JSON.parse(myCache.get({

key: 'usedCMIDs',

ttl: 18000



Rookie Asked on September 19, 2019 in SuiteScript.

Could you set a custom field in beforeSubmit with whatever you need, and then get the value in afterSubmit?

on September 19, 2019.
Add Comment
2 Answer(s)

I wouldn’t recommend using the cache module for this. The intended use of the module is to improve performance, not as a messaging mechanism between scripts. Notably, whilst you are able to specify a TTL, NetSuite makes no guarantee that the data will not be removed earlier, so even if it works 99% of the time it’s not best practice and can lead to hard to track bugs in the future.

Advanced Answered on September 19, 2019.

Fair enough! So what is your alternative to passing value between BeforeSubmit and AfterSubmit functions of the same script??

edit: nevermind, I found the answer by myself

on September 20, 2019.
Add Comment

Based on a SuiteAnswers article I found, this is a recommended method. [SS1.x] Pass a Value from the Before Submit to the After Submit Script

I tested the code myself and as @michoel pointed out about the not guaranteed TTL, this SESSION method does not have a TTL.


var sessionObj = runtime.getCurrentSession();
name: "myKey",
value: "myValue"
log.debug("Session object myKey value: " + sessionObj.get({name: "myKey"});
Rookie Answered on September 20, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor