Overview
NetSuite does not provide a native QR code generator, but you can easily implement one using a Suitelet and a free QR code API. This approach is useful for mobile access to Suitelets by scanning QR codes instead of typing URLs.
Solution Approach
We will:
- Create a Suitelet that displays multiple external links.
- Dynamically resolve each Suitelet’s external URL using N/url.
- Generate QR codes using the QRServer API.
- Display the QR code and clickable link in the Suitelet form using INLINEHTML fields.
Key API Used
- QRServer API:
- https://api.qrserver.com/v1/create-qr-code/?size=150×150&data=<encoded-url>
Suitelet code for Generating QR Codes for Suitelet External Links in NetSuite
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
define([‘N/ui/serverWidget’, ‘N/url’], function (ui, url) {
function onRequest(scriptContext) {
// Create the form
let form = ui.createForm({
title: ‘Mobile Access QR CODE’
});
// Define external Suitelet links
let externalLinks = [
{ title: ‘Job Processing Page’, scriptId: ‘customscriptjj_sl_home_page_steri203’, deployId: ‘customdeployjj_sl_steri203’ },
{ title: ‘SVO Tracker Dallas’, scriptId: ‘customscript_jj_sl_svo_dallas_steri_284’, deployId: ‘customdeploy_jj_sl_svo_dallas_steri_284’ }, ];
// Loop through each link and generate QR code
for (let i = 0; i < externalLinks.length; i++) {
let linkObj = externalLinks[i];
// Resolve external URL for the Suitelet
let resolvedUrl = url.resolveScript({
scriptId: linkObj.scriptId,
deploymentId: linkObj.deployId,
returnExternalUrl: true
});
// Generate QR code URL
let qrCodeUrl = ‘https://api.qrserver.com/v1/create-qr-code/?size=150×150&data=’ + encodeURIComponent(resolvedUrl);
// Add an Inline HTML field to display link and QR code
form.addField({
id: ‘custpage_qr_’ + i,
type: ui.FieldType.INLINEHTML,
label: linkObj.title
}).defaultValue =
‘<div style=”padding-top:40px;text-align:center;”>’ +
‘<p><strong><a href=”‘ + resolvedUrl + ‘” target=”_blank” style=”font-size:24px;”>’ + linkObj.title + ‘</a></strong></p>’ +
‘<img src=”‘ + qrCodeUrl + ‘” alt=”QR Code for ‘ + linkObj.title + ‘” />’ +
‘</div>’;
}
// Render the form
scriptContext.response.writePage(form);
}
return {
onRequest: onRequest
};
});
How It Works
- url.resolveScript() dynamically generates the external URL for each Suitelet deployment.
- encodeURIComponent() ensures the URL is properly encoded for the QR API.
- The QR code image is embedded in the form using an INLINEHTML field.
Benefits
- Quick mobile access to Suitelets without typing URLs.
- Easy to extend for additional links.
- Uses a free and reliable QR code API.