Tuesday, September 4, 2018

Set the Value of a Field on the Case Re... a Customer Responds to the Case Email


When a customer responds to a case email, NetSuite creates a new Message record with a reference to the case but no changes are made to the case record, therefore, user event scripts and workflows deployed to the case record are not triggered.
The steps below show how to create a user event script and deploy it to Messages to change the status of the case to Re­Opened when a customer updates the case via email:
­ Use the script below to create a JavaScript file (.js) and upload it the SuiteScripts folder in the File Cabinet:
function afterSubmit(type) {
// Load the message record
var message = nlapiGetNewRecord();

// Get the ID of the activity associated with the message var activity = message.getFieldValue('activity');
// If there is any activity if(activity)
{

// If the activity is a case, load the record and change the status. try
{

var caseRecord = nlapiLoadRecord('supportcase', activity); caseRecord.setFieldValue('status',4); nlapiSubmitRecord(caseRecord);
}
// If the activity is not a Case, log a warning message catch(exec)
{

nlapiLogExecution('DEBUG', 'Warning','Activity Record is not a Case'); }
} }
­ Create a script record and deploy it to Messages:
1. Go to Customization > Scripting > Scripts > New. 2. Select User Event.
3. In the Name field, enter
UE Message.
4. Under the
Scripts tab:

In the Script File field, select the JavaScript file created before. In the After Submit Function field, enter afterSubmit
5. Under the Deployments tab, create a new deployment:
Applied To = Message Deployed = Yes Status = Released Log Level = Debug

No comments:

Post a Comment