通过使用Suitelet脚本

时间:2015-08-12 14:05:18

标签: netsuite

概述:

我使用Suitelet脚本创建了一个自定义客户表单,其中包含GET方法中的名称,电子邮件,电话等字段,以及在POST方法中通过request.getParameter()方法获得的值。创建客户记录是成功的,但是当单击提交按钮时,客户记录将是"非活动"模式和URL链接将被发送到客户的电子邮件地址,当他点击链接时,他的记录将被更改为" active"模式必须与相同的suitelet页面相同。

我的要求:

我使用INACTIVE MODE成功创建了客户记录,并将此链接发送给客户邮件,但我需要如何在客户点击链接时将客户记录设置为ACTIVE MODE,并且结果将在同一个suitelet页面中查看。

我已经给出了我的代码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 个答案:

答案 0 :(得分:1)

听起来您基本上想要的是向客户发送确认链接,他们可以点击并完成某种注册。

如果要重新使用套件代码,则需要传递可以触发不同操作的自定义阶段或操作参数。 e.g:

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

然后您需要发送的网址需要引用套件而不是Netsuite中的客户页面:

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

函数getSecureValidationParams应创建某种时间敏感参数,包括散列键。如果请求通过验证,那么您将显示您要显示或重定向到或显示感谢页面的任何其他表单。

答案 1 :(得分:0)

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);

    }

以上代码将通过外部Suitelet表单获取客户信息,并将记录保存在系统中。