The code below serves the following purposes:
1) Auto approve credit card orders under function SOCreditReview(type){
try {
//Do only on create.
if ( type != 'create' )
{
return true;
}
var emailtrue = new Boolean;
var emailsubject = new String
var emailbody = new String
var transactiondescription = new String
var integrationstatus = new String
emailtrue = "F"
emailsubject = ""
emailbody = ""
//Max amount we will auto approve
autoapproveamount = 250
//soautoapprove needs a value of 6 to be autoapproved
soautoapprove = 0
//Get the InternalId of the Sales Order
var tranRecordId = nlapiGetRecordId();
//Load the sales order
var tranRecord = nlapiLoadRecord('salesorder',tranRecordId);
tranNumber = tranRecord.getFieldValue('tranid')
//Set the transactiondescription in case we have a fatal error
transactiondescription = "Sales Order =" + tranNumber
//Try to use the confirmation number that customer would see
if (tranRecord.getFieldValue('memo') != null && tranRecord.getFieldValue('memo') != "") {
tranConfirmNumber = tranRecord.getFieldValue('memo')
}
else {
tranConfirmNumber = tranNumber
}
//Let's see if we can auto approve the order, there are many variables, lets separate for readability.
//Rather than use true / false, count to 6
//3=Discover, 4=Master Card, 5=VISA, 6=American Express are the only payment methods
if (tranRecord.getFieldValue('paymentmethod')>=3 && tranRecord.getFieldValue('paymentmethod')<=6)
soautoapprove += 1
//bill to = ship to?
if (tranRecord.getFieldValue('billaddress')==tranRecord.getFieldValue('shipaddress'))
soautoapprove += 1
//AVS match?
if (tranRecord.getFieldValue('ccavsstreetmatch')=="Y" && tranRecord.getFieldValue('ccavszipmatch')=="Y")
soautoapprove += 1
//CVV match?
if (tranRecord.getFieldValue('ccsecuritycodematch')=="Y")
soautoapprove += 1
//of course, card approved?
if (tranRecord.getFieldValue('ccapproved')=="T")
soautoapprove += 1
//is total less than the auto approve threshold?
if (tranRecord.getFieldValue('total')<autoapproveamount)
soautoapprove += 1
// if soautoapprove = 6 then we can approve and send an email.
if (soautoapprove == 6)
{
tranRecord.setFieldValue('orderstatus',"B")
nlapiSubmitRecord(tranRecord)
emailsubject = "NetSuite Message: Order# " + tranNumber + " was auto approved."
emailbody = "billaddress=shipaddress" + "\n"
emailbody += "ccavsstreetmatch=True" + "\n"
emailbody += "ccavszipmatch=True" + "\n"
emailbody += "ccsecuritycodematch=True" + "\n"
emailbody += "ccapproved=True" + "\n"
emailbody += "total<" + autoapproveamount + "\n"
nlapiSendEmail(3328, 'service@.com', emailsubject, emailbody)
//our job is done, let's return
return
}
//We cannot auto approve, let's see if we need to send some emails related to credit card information
emailsubject = "Your order no. " + tranConfirmNumber + " Requires your attention."
emailtrue = "F"
var vpaymentmethod= new String
vpaymentmethod=""
//convert the payment method to usable values
switch (tranRecord.getFieldValue('paymentmethod'))
{
case '3': {vpaymentmethod='Discover'; break;}
case '4': {vpaymentmethod='MasterCard'; break;}
case '5': {vpaymentmethod='VISA'; break;}
case '6': {vpaymentmethod='American Express'; break;}
default : {vpaymentmethod='Unknown'; break;}
}
//if this is a credit card, then test bill to and avs
if (tranRecord.getFieldValue('ispaymethcc')=="T")
{
var fields = new Array();
fields['NLCARDTYPE'] = vpaymentmethod
fields['NLBILLPHONE'] = tranRecord.getFieldValue('billphone')
//If bill to <> ship to send email
if (tranRecord.getFieldValue('billaddress')!=tranRecord.getFieldValue('shipaddress'))
{ emailtrue = "T"
emailbody = nlapiMergeRecord( 19, 'salesorder', tranRecordId, null, null, fields).getValue();
}
// If avs mismatch, then this is more important to email
if (tranRecord.getFieldValue('ccavsstreetmatch')!="Y" || tranRecord.getFieldValue('ccavszipmatch')!="Y")
{ emailtrue = "T"
emailbody = nlapiMergeRecord( 17, 'salesorder', tranRecordId, null, null, fields).getValue();
}
}
//If this is a paypal order over $250, email permission to use UPS signature required.
if (tranRecord.getFieldValue('ispaypal')=="T" && tranRecord.getFieldValue('total')>250)
{ emailtrue = "T"
emailbody = nlapiMergeRecord( 18, 'salesorder', tranRecordId, null, null, null).getValue();
}
if (emailtrue == "T") {
var records = new Array();
records['entity'] = tranRecord.getFieldValue('entity');
records['transaction'] = tranRecordId;
var email = new String
if (tranRecord.getFieldValue('email') == null) {
email = "service@.com"
emailsubject = "No Email Address on Sales Order -- " + emailsubject
}
else
email = tranRecord.getFieldValue('email')
nlapiSendEmail(6622, email, emailsubject, emailbody, null, null, records);
}
}
catch (error) {
if (error.getDetails != null)
CreateFormattedExceptionMsg(error, transactiondescription);
else
CreateFormattedExceptionMsg(error.description, transactiondescription);
}
finally {}
}
50
2) Email credit card customer when AVS=N
3) Email credit card customer when bill to and ship to do not match
4) Email PayPal customer when order amount > function SOCreditReview(type){
try {
//Do only on create.
if ( type != 'create' )
{
return true;
}
var emailtrue = new Boolean;
var emailsubject = new String
var emailbody = new String
var transactiondescription = new String
var integrationstatus = new String
emailtrue = "F"
emailsubject = ""
emailbody = ""
//Max amount we will auto approve
autoapproveamount = 250
//soautoapprove needs a value of 6 to be autoapproved
soautoapprove = 0
//Get the InternalId of the Sales Order
var tranRecordId = nlapiGetRecordId();
//Load the sales order
var tranRecord = nlapiLoadRecord('salesorder',tranRecordId);
tranNumber = tranRecord.getFieldValue('tranid')
//Set the transactiondescription in case we have a fatal error
transactiondescription = "Sales Order =" + tranNumber
//Try to use the confirmation number that customer would see
if (tranRecord.getFieldValue('memo') != null && tranRecord.getFieldValue('memo') != "") {
tranConfirmNumber = tranRecord.getFieldValue('memo')
}
else {
tranConfirmNumber = tranNumber
}
//Let's see if we can auto approve the order, there are many variables, lets separate for readability.
//Rather than use true / false, count to 6
//3=Discover, 4=Master Card, 5=VISA, 6=American Express are the only payment methods
if (tranRecord.getFieldValue('paymentmethod')>=3 && tranRecord.getFieldValue('paymentmethod')<=6)
soautoapprove += 1
//bill to = ship to?
if (tranRecord.getFieldValue('billaddress')==tranRecord.getFieldValue('shipaddress'))
soautoapprove += 1
//AVS match?
if (tranRecord.getFieldValue('ccavsstreetmatch')=="Y" && tranRecord.getFieldValue('ccavszipmatch')=="Y")
soautoapprove += 1
//CVV match?
if (tranRecord.getFieldValue('ccsecuritycodematch')=="Y")
soautoapprove += 1
//of course, card approved?
if (tranRecord.getFieldValue('ccapproved')=="T")
soautoapprove += 1
//is total less than the auto approve threshold?
if (tranRecord.getFieldValue('total')<autoapproveamount)
soautoapprove += 1
// if soautoapprove = 6 then we can approve and send an email.
if (soautoapprove == 6)
{
tranRecord.setFieldValue('orderstatus',"B")
nlapiSubmitRecord(tranRecord)
emailsubject = "NetSuite Message: Order# " + tranNumber + " was auto approved."
emailbody = "billaddress=shipaddress" + "\n"
emailbody += "ccavsstreetmatch=True" + "\n"
emailbody += "ccavszipmatch=True" + "\n"
emailbody += "ccsecuritycodematch=True" + "\n"
emailbody += "ccapproved=True" + "\n"
emailbody += "total<" + autoapproveamount + "\n"
nlapiSendEmail(3328, 'service@.com', emailsubject, emailbody)
//our job is done, let's return
return
}
//We cannot auto approve, let's see if we need to send some emails related to credit card information
emailsubject = "Your order no. " + tranConfirmNumber + " Requires your attention."
emailtrue = "F"
var vpaymentmethod= new String
vpaymentmethod=""
//convert the payment method to usable values
switch (tranRecord.getFieldValue('paymentmethod'))
{
case '3': {vpaymentmethod='Discover'; break;}
case '4': {vpaymentmethod='MasterCard'; break;}
case '5': {vpaymentmethod='VISA'; break;}
case '6': {vpaymentmethod='American Express'; break;}
default : {vpaymentmethod='Unknown'; break;}
}
//if this is a credit card, then test bill to and avs
if (tranRecord.getFieldValue('ispaymethcc')=="T")
{
var fields = new Array();
fields['NLCARDTYPE'] = vpaymentmethod
fields['NLBILLPHONE'] = tranRecord.getFieldValue('billphone')
//If bill to <> ship to send email
if (tranRecord.getFieldValue('billaddress')!=tranRecord.getFieldValue('shipaddress'))
{ emailtrue = "T"
emailbody = nlapiMergeRecord( 19, 'salesorder', tranRecordId, null, null, fields).getValue();
}
// If avs mismatch, then this is more important to email
if (tranRecord.getFieldValue('ccavsstreetmatch')!="Y" || tranRecord.getFieldValue('ccavszipmatch')!="Y")