Add a Custom Button to Execute a Suitelet
The following sample shows how to add a button to a sales order in Pending Fulfillment status.
For the complete tutorial, see Add Custom Button to Execute a Suitelet.
Important:
This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/runtime', 'N/log'], (runtime, log) => {
function beforeLoad(scriptContext) {
try {
const recCurrent = scriptContext.newRecord;
const objForm = scriptContext.form;
const stStatus = recCurrent.getValue({
fieldId: 'status'
});
const stSuiteletLinkParam = runtime.getCurrentScript().getParameter({
name: 'custscript_suiteletlink'
});
const suiteletURL = '\"' + stSuiteletLinkParam + '\"';
if (stStatus === 'Pending Fulfillment') {
objForm.addButton({
id: 'custpage_suiteletbutton',
label: 'Open Suitelet',
functionName : 'window.open(' + suiteletURL + ')',
});
}
} catch(error) {
log.error({
title: 'beforeLoad_addButton',
details: error.message
});
}
}
return {
beforeLoad: beforeLoad
};
});