NetSuite: Suite.js Interactive Inventory Inquiry Example

Published on January 30, 2025.

Yesterday I posted to LinkedIn an interesting Suite.js use case: An interactive, retro-style NetSuite inventory inquiry app.

The user enters an item number, and the description, quantity available, and unit price is displayed. The app integrates with NetSuite using SuiteAPI, and gets the item information via a simple SuiteQL query.

Here's an example.

Click the image to view a larger version.

Several LinkedIn followers reached out to me and asked what the JavaScript code for that app looks like. I've included it below.

If you're not familiar with Suite.js, it's a JavaScript runtime that's designed specifically for NetSuite integration projects. It's especially helpful when it comes to developing apps that automate batch-like, input/output intensive NetSuite processes.

Suite.js will be available for public beta testing in February.

You can learn more about the project here: https://suitejs.io

writeln;
writeln( '----------------------------------------------------------------------------------------------------' );
writeln( 'NetSuite / Suite.js Inventory Inquiry' );
writeln( '----------------------------------------------------------------------------------------------------' );
writeln;

var nsCredentials = {
	accountNumber: '9999999_SB1',
	consumerKey: '*** your consumer key ***',
	consumerSecret: '*** your consumer secret ***',
	tokenID: '*** your token id ***',
	tokenSecret: '*** your token secret ***'	
}

var nsRESTletURL = 'https://9999999-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=99999&deploy=1'

var query = <<<TEXTBLOCK
	SELECT
		Item.ID AS Item,
		Item.ItemID,
		Item.DisplayName,
		( SELECT SUM( QuantityAvailable ) FROM AggregateItemLocation WHERE ( AggregateItemLocation.Item = Item.ID ) ) AS TotalQuantityAvailable,
		InvtItemPriceHistory.Price
	FROM 
		Item
		LEFT OUTER JOIN InvtItemPriceHistory ON
			( InvtItemPriceHistory.Item = Item.ID )
			AND ( InvtItemPriceHistory.PriceType = 8 )
			AND ( InvtItemPriceHistory.Version = -1 )			
	WHERE
		( Item.ItemID = ? )
TEXTBLOCK>>>	

var curlProperties = {}
curlProperties.OptionCustomRequest = "POST";
curlProperties.OptionURL = nsRESTletURL;
curlProperties.OptionHeaders = { 
	"Content-Type": "application/json"
};
curlProperties.NetsuiteCredentials = nsCredentials;

while ( true ) {

	writeln( 'Part Number:' );
	
	var partNumber = prompt();
	
	writeln;
	
	if ( partNumber == 'quit' ) {
		abort;
	}
	
	var curlPayload = {
	  procedure: "queryRun",
	  query: query,
	  params: [ partNumber ]
	}		
	
	curlProperties.OptionPostFields = JSON.stringify( curlPayload );
	
	curlExecute( curlProperties );
	
	var outputJSON = JSON.parse( curl.output );
	
	var item = outputJSON.records[0];
	
	if ( item === undefined ) {
		writeln( partNumber + ' was not found.' );
		writeln;
	} else {

		writeln( 'Description: ' );
		writeln( item.displayname );
		writeln;
		writeln( 'Qty Available: ');
		writeln( '' + item.totalquantityavailable );
		writeln;
		writeln( 'Unit Price: ' );
		writeln( '$' + item.price );
		writeln;	
		
	}
		
	writeln( '----------------------------------------------------------------------------------------------------' );
			
}
About Me

Hello, I'm Tim Dietrich. I develop custom software for businesses that are running on NetSuite, including mobile apps, Web portals, Web APIs, and more.

I'm the developer of several popular NetSuite open source solutions, including the SuiteQL Query Tool, SuiteAPI, and more.

I founded SuiteStep, a NetSuite development studio, to provide custom software and AI solutions - and continue pushing the boundaries of what's possible on the NetSuite platform.

Copyright © 2025 Tim Dietrich.