Tuesday, April 23, 2019

SuiteScript> Set Preferred Transactions within the Customer that Triggers Transaction Emails

To set preferred transactions within the Customer that triggers transaction emails, we can create a custom field within the customer record that lets users choose transactions that would allow the system to send email. We can then create a script that checks the custom field and allows or disallows sending of email for the customer's transaction.
1. Create a custom entity field that would contain the different transaction
types (Customizations> Lists, Records, & Fields >  Entity Fields > New)
a. Label -> Send Transactions For
b. Type -> Multiple Select
c. List/Record -> Transaction Type
d. Store Value -> Checked
e. Applies To > Customer -> Checked
f.  Display > Subtab -> Preferences
2. Save new custom field.
3. Create a user event script that checks whether the customer would like to
receive an email for the transaction based on the custom field created above.

Below is a sample script that can be deployed to transaction records:

function beforeSubmit(type) {
 nlapiLogExecution('DEBUG','Before Submit','type = '+type);
 if (type=='create'){
  var cust = nlapiLoadRecord('customer',nlapiGetFieldValue('entity'));
  var tran_for_email = new Array();
  tran_for_email = trimSpaces(cust.getFieldTexts('custentity_sendtransactionsfor'));
  if (tran_for_email.indexOf(nlapiGetRecordType())<0){
   nlapiLogExecution('DEBUG','Do not Send Email',nlapiGetFieldValue('tobeemailed'));
  } else {
   nlapiLogExecution('DEBUG','Email Sent',nlapiGetFieldValue('tobeemailed'));
function trimSpaces(type_array){
 var newtype_array = new Array();
 for (var i=0; i<type_array.length; i++){
  newtype_array[i] = type_array[i].replace(/\s+/g,'').toLowerCase();
 return newtype_array;

No comments:

Post a Comment