Add new comment

While creating my first Suitelet to create a new customer, I've ran into a couple of problems. Here are the problems I've run into and the solutions.

1. Error #1: You do not have privileges to view this page

When the external Suitelet URL is clicked from the Netsuite Suitelet deployment page, the above error message is displayed. This is due to the Suitelet is not properly deployed with correct audiences.

To fix this problem, you'll have to modify the audiences. Make sure you do not choose any department or partners.

2. Error #2: Invalid entitystatus reference key 6.

Since we are creating a new customer of type Lead from an external website, we would like to create a customer with an entity status of Lead-Unqualified (Internal ID=6). However, whatever the reason the Suitelet wouldn't assign the correct entitystatus to the newly creating customer. Here is the code we've used.

function CreateCustomer(request, response)   {
	
    if (request.getMethod() == 'POST') {
    	var customer = nlapiCreateRecord('customer');
    	customer.setFieldValue('isperson', 'T');
    	customer.setFieldValue('customform', '3'); // Sales Lead Form
    	customer.setFieldValue('entitystatus', '6');    // LEAD::unqualified.
    	customer.setFieldValue('firstname', request.getParameter('firstname'));
    	customer.setFieldValue('lastname', request.getParameter('lastname'));
    	customer.setFieldValue('companyname', request.getParameter('companyname'));
    	customer.setFieldValue('phone', request.getParameter('phone'));
    	customer.setFieldValue('email', request.getParameter('email'));
    	var customerId = nlapiSubmitRecord(customer, true);
    }
}

To workaround this problem, we would create a customer with a default status (Customer-Closed Won) and then reload the customer for an update. Here is an updated Suitelet code that does the job we want.

function CreateCustomer(request, response)   {
	
    if (request.getMethod() == 'POST') {
    	var customer = nlapiCreateRecord('customer');
    	customer.setFieldValue('isperson', 'T');
    	customer.setFieldValue('customform', '3'); // Sales Lead Form
    	//customer.setFieldValue('entitystatus', '6');    // LEAD::unqualified.
    	customer.setFieldValue('firstname', request.getParameter('firstname'));
    	customer.setFieldValue('lastname', request.getParameter('lastname'));
    	customer.setFieldValue('companyname', request.getParameter('companyname'));
    	customer.setFieldValue('phone', request.getParameter('phone'));
    	customer.setFieldValue('email', request.getParameter('email'));
    	var customerId = nlapiSubmitRecord(customer, true);
    	var cust = nlapiLoadRecord("customer", customerId);
    	cust.setFieldValue('entitystatus', '6');
    	nlapiSubmitRecord(cust);
    }
}
By Scott Seong (not verified)

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.