Learn SuiteCommerce Advanced SuiteScript Server Pages SSP Fundamentals

This article is relevant if your are seeking to understand the basics of NetSuite SuiteScript Server Page technologies.

Background

NetSuite’s release of SuiteScript Server Pages (SSP) for eCommerce applications is a welcome capacity. While NetSuite offers a number of SuiteBundles to enhance your Site Builder web site, the reference applications are complex to understand for even seasoned software developers. It’s helpful to learn some fundamentals when working with the technology to help ground how you can build your own applications and customizations. This article is designed to move away NetSuite’s complex examples and produce a simple “Hello World” sample to help you learn.

SSP and SS Pages

NetSuite offers two SuiteScript page extensions to drive the environment. Based on documentation and provided code examples, you may be led to believe the following:

  1. SS pages are for server side script
  2. SSP pages are for client side script

This way of thinking about the technology does not really help as it will limit how you can use the tools. Instead, I suggest thinking about these two page types as follows:

  1. SS pages are server side page request handlers and can be thought to be close to NetSuite RESTlets in their programming model. They do not require authentication and they can output any string — you are not limited to JSON data formats.
  2. SSP pages allow for the convenient mixture of HTML with server side script. They look similar to many other web programming languages including early web languages such as Microsoft’s Classic ASP; These pages can do everything an SS page can; yet they offer more flexibility.

In my mind, given their flexibility, SSP pages can be used to drive your application development.

Deeper Understanding of the SSP & SS Technology

The key to understand how these pages work is to first understand the SS page structure. Effectively, one function call in the script page starts the action:

function service (request, response){
}

The “service” function is akin to a “main” program that gets called by the environment when a page is executed. The “request” and “response” parameters pass references objects which are NetSuite’s nlobjRequest and nlobjResponse objects respectively supporting the full functional syntax in this environment.

How SSP Hides SS Technology Constructs

What is not obvious is that SSP pages effectively are preprocessed and organized into one big “service” call to execute all of your code. All places where you had HTML embedded is reorganized into behind the scenes response.write(<your html>) calls. More importantly, the SSP pages expose the request and response objects for your consumption and use — yet it is not obvious they are available. Because of this preprocessing context for which these pages are produced, you need to be careful how you call these Request and Response objects as you craft your pages.

Example HTML and SSP Pages

NetSuite’s Help document suggests that SSP pages are used in HTTP GET calls; they imply that SSP pages do not support HTTP POST. Our experience and code example below will illustrate that SSP pages accept POST. Further, the code example is meant to help you see how you can mix programming types to utilize the request and response objects in the development environment.

To get this code to run, you will need to move these pages into any SSP Application directory. Based on your SSP Application setup, you should be able to determine the web site path name to fire the script. Here are two live examples

HTML Page with some Server Side Functions

http://store.btc4erp.com/BTC4ERP-DEV/20140920/post-20150412.html

<html>
<head><%=getPageFullHead()%></head>
<body>
<table cellpadding=0 cellspacing=0 border=0 width=100%><NLPAGETOP></table>
<h1>Post to SSP Page Example</h1>

<form method="post" target="_blank" action="./page-20150412.ssp">

Payment Method:
<select name="paymentmethod">
	<option value="Visa">Visa</option>
	<option value="Mastercard">MasterCard</option>
	<option value="Amex">Amex</option>
</select>
<br>
CCNumber: 
<input type="text" name="ccnumber" value="4111111111111111">
<br>
CCName:
<input type="text" name="ccname" value = "Marty Zigman">
<br>
Expires: 
<select name="ccexpiremonth">
	<option value="01">January</option>
	<option value="02">February</option>
	<option value="03">March</option>
	<option value="04">April</option>
</select>
<select name="ccexpireyear">
	<option value="2015">2015</option>
	<option value="2016">2016</option>
	<option value="2017">2017</option>
	<option value="2018">2018</option>
</select>
<br>
CVV Code: 
<input type="text" name="cccvs" value = "0976"><br>
NetSuite Sales ORDER ID 
<input type="number" name="order_id" value = "20550">
CUSTOMER ID 
<input type="number" name="customer_id" value = "1769"><br>
Submit as POST to page-20150412.ssp<br>
<input type="submit" name="submit"><br>

</form>
</body>
</html>

Receiving SSP Pages Capturing the HTTP Post

http://store.btc4erp.com/BTC4ERP-DEV/20140920/page-20150412.ssp

<html>
<head><%=getPageFullHead()%></head>
<body>
<table cellpadding=0 cellspacing=0 border=0 width=100%><NLPAGETOP></table>

<h1>Hello World</h1>
Value of request getURL <%=request.getURL()%>;

<h2>Context Variables</h2>
<% 
	var context = nlapiGetContext();
	//var name = context.getName();
	var params = request.getAllParameters();
	//response.writeLine('getName in page-20150412.ssp: ' + context.getName() );
	response.write('getName: ' + context.getName() + '<br>');
	response.write('getUser: ' + context.getUser() + '<br>');
	response.write('getRole: ' + context.getRole() + '<br>');
	response.write('getRoleCenter: ' + context.getRoleCenter());

	nlapiLogExecution("DEBUG", "getName", context.getName()) 
	nlapiLogExecution("DEBUG", "getUser", context.getUser()) 
	nlapiLogExecution("DEBUG", "getRole", context.getRole())
	nlapiLogExecution("DEBUG", "getRoleCenter", context.getRoleCenter())
%>

<h2> Parameters</h2>

<% for ( param in params ) {
 	response.write('parameter: ' + param + '; value: ' + params[param] + '<br>')  
} %>

</body>
</html>

Get Help with your Suite Commerce SuiteScript Server Pages Applications

If you are would like to drive more value out of your NetSuite Site Build and SuiteCommerce Advanced eCommerce systems, let’s setup a conversation.

Be Sociable, Share!

Marty Zigman

Holding all three official certifications, Marty is regarded as the top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. He is a former Deloitte & Touche CPA and has held CTO roles. For over 30 years, Marty has produced leadership in ERP, CRM and eCommerce business systems. Contact Marty to set up a conversation.

More Posts - Website - Twitter - Facebook - LinkedIn - YouTube

| Tags: , , , , , | Category: NetSuite, Technical | 1 Comment

One thought on “Learn SuiteCommerce Advanced SuiteScript Server Pages SSP Fundamentals

Leave a Reply

Your email address will not be published. Required fields are marked *