0
votes

Overview:

I create one custom customer form using Suitelet Script with fields like name,email,phone in GET Method and the values entered in this fields obtained in the POST Method by request.getParameter() method. the customer record is created is successfully but when clicking the submit button the customer record is to be "inactive" mode and the url link is to sent to the customer email address ,when he clicks the link his record is to be changed to"active" mode this must be with in same suitelet page.

My Requirement:

I created the customer record successfully with INACTIVE MODE and link this send the customer mail but i need how to make the customer record to ACTIVE MODE when he clicks the link and the result is to be viewed in same suitelet page.

I have Given my code Sample Below:

function getCustomerInfo(request, response){
       if(request.getMethod() == 'GET'){
    	   //CREATING THE CUSTOM FORM AND ADDING FIELDS IN THE FORM
    	   var form = nlapiCreateForm('Custom Customer Form');
           form.addField('sfg_company', 'text', 'Company Name').setMandatory(true);
           form.addField('sfg_address1','text','Address1');
           form.addField('sfg_address2','text','Address2');
           form.addField('sfg_city','text','City');
           form.addField('sfg_state','text','State');
           form.addField('sfg_emailaddr','email','Email').setMandatory(true);
           form.addField('sfg_phone','phone','Phone');
           form.addSubmitButton('Submit');
           response.writePage(form);
           
        }else{
        	nlapiLogExecution('DEBUG','form',form);
        	// CREATING THE RECORD BY GETTING THE VALUES ENTERED IN THE CUSTOM FORM
        	 var compName = request.getParameter('sfg_company');
             var compAdd1 = request.getParameter('sfg_address1');    
             var compAdd2 = request.getParameter('sfg_address2');   
             var cities = request.getParameter('sfg_city');
             var stateName =request.getParameter('sfg_state');
             var email_addr = request.getParameter('sfg_emailaddr');
             var phone_num  = request.getParameter('sfg_phone');
             var newCust = nlapiCreateRecord('customer');
             newCust.setFieldValue('companyname', compName);
             newCust.setLineItemValue('addressbook', 'addr1', 1, compAdd1);
             newCust.setLineItemValue('addressbook', 'addr2', 1, compAdd2);
             newCust.setLineItemValue('addressbook', 'city', 1, cities);
             newCust.setLineItemValue('addressbook', 'state', 1, stateName);
             newCust.setFieldValue('email', email_addr);
             newCust.setFieldValue('phone', phone_num);
             newCust.setFieldValue('subsidiary', 1);
             newCust.setFieldValue('isinactive','T');
             //sending activation link to the customer
             var sender = nlapiGetUser();
             var receiver =  email_addr;
             var subject = 'Customer Activation Link';
             var recordId = nlapiGetRecordId();
             var url = "https://system.na1.netsuite.com/app/common/entity/custjob.nl?id="+recordId+"&whence=";
             var body = 'Dear Customer,Your Record is Created Successfully and it will activated by click the following link :'+ url;
             nlapiSendEmail(sender,receiver,subject,body);
             var id = nlapiSubmitRecord(newCust);
             nlapiSetRedirectURL('RECORD','customer',id,null,false);
        	
        }
    	   	
   }
2

2 Answers

1
votes

It sounds like what you basically want is to send out a confirmation link to a customer that they can click and complete some sort of registration.

If you want to re-use your suitele code then you need to pass a custom stage or action parameter that you can trigger different actions from. e.g.:

var stage = request.getParameter('custparam_action') || 'showForm';
switch(stage){
  case 'showForm': doShowForm(request, response); break;
  case 'validate' : doValidate(request, response); break;
}...

Then the url you need to send out needs to reference the suitelet rather than the customer page in Netsuite:

var ctx = nlapiGetContext();
var url = nlapiResolveURL('SUITELET', ctx.getScriptId(), ctx.getDeploymentId(), true) +"&custparam_action=validate"+ getSecureValidationParams());

the function getSecureValidationParams should create some sort of time sensitive parameters including a hashed key. If the request passes validation then you would show whatever other form you want to show or redirect to or show a thank you page.

0
votes
function getCustomerInfo(request, response){
    if(request.getParameter('custscript_sfg_custmer_param') != null){
        var value = request.getParameter('custscript_sfg_custmer_param')
        var loadRecord = nlapiLoadRecord('customer',value);
        loadRecord.setFieldValue('isinactive','F');
                loadRecord.setFieldValue('custentity_sfg_referredby',1);
        nlapiSubmitRecord(loadRecord);
        nlapiSetRedirectURL('RECORD','customer',value);
    }
    if(request.getParameter('custscript_sfg_custmer_param') == null){
        if(request.getMethod() == 'GET'){
               //CREATING THE CUSTOM FORM AND ADDING FIELDS IN THE FORM
               var form = nlapiCreateForm('Custom Customer Form');
               form.addField('sfg_company', 'text', 'Company Name').setMandatory(true);
               form.addField('sfg_address1','text','Address1');
               form.addField('sfg_address2','text','Address2');
               form.addField('sfg_city','text','City');
               form.addField('sfg_state','text','State');
               form.addField('sfg_emailaddr','email','Email').setMandatory(true);
               form.addField('sfg_phone','phone','Phone');
               form.addSubmitButton('Submit');
               response.writePage(form);        
    }
   }
    if(request.getMethod() == 'POST'){
        nlapiLogExecution('DEBUG','form',form);
        // CREATING THE RECORD BY GETTING THE VALUES ENTERED IN THE CUSTOM FORM
         var compName = request.getParameter('sfg_company');
         var compAdd1 = request.getParameter('sfg_address1');    
         var compAdd2 = request.getParameter('sfg_address2');   
         var cities = request.getParameter('sfg_city');
         var stateName =request.getParameter('sfg_state');
         var email_addr = request.getParameter('sfg_emailaddr');
         var phone_num  = request.getParameter('sfg_phone');
         var newCust = nlapiCreateRecord('customer');
         newCust.setFieldValue('companyname', compName);
         newCust.setLineItemValue('addressbook', 'addr1', 1, compAdd1);
         newCust.setLineItemValue('addressbook', 'addr2', 1, compAdd2);
         newCust.setLineItemValue('addressbook', 'city', 1, cities);
         newCust.setLineItemValue('addressbook', 'state', 1, stateName);
         newCust.setFieldValue('email', email_addr);
         newCust.setFieldValue('phone', phone_num);
         newCust.setFieldValue('subsidiary', 1);
         newCust.setFieldValue('isinactive','T');
         //sending activation link to the customer
         var sender = nlapiGetUser();
         var receiver =  email_addr;
         var subject = 'Customer Activation Link';
         var recordId = nlapiGetRecordId();
         var webAddress = "https://system.na1.netsuite.com"
         var scriptType = nlapiGetContext().getScriptId();
         var scriptId = nlapiGetContext().getDeploymentId();
         var location = nlapiResolveURL('SUITELET',scriptType,scriptId);
         var id = nlapiSubmitRecord(newCust);
         var link = webAddress+location+'&custscript_sfg_custmer_param='+id+"&whence=";
         var url = '<a href="'+link+'">Click Here </a>';
         var body = 'Dear Customer,Your Record is Created Successfully and it will activated by click the following link :'+ url;
         nlapiSendEmail(sender,receiver,subject,body);
         nlapiSetRedirectURL('SUITELET',scriptType,scriptId);

    }

The above code will Get Customer Information through external Suitelet form and saving the record in the system.