Sample SuiteScript 2.0 code to Dynamically Create Button to Fire Two SuiteLets
In the code example below, using SuiteScript 2.0 it is relatively easy to see how you can hook up a button to fire not one, but two SuiteLets. The first Suitelet does not have a user interface and performs work server side. The second SuiteLet will draw in a new browser window and display its output.
const CREPROFILE = 65;
//get the url for the suitelet #1; add customer parameter recId based on this ID
var buildURL = url.resolveScript({
'scriptId':'customscript_sl_build_inf',
'deploymentId':'customdeploy_sl_build_inf',
'returnExternalUrl': true
}) + '&recId=' + REC.getValue("id");
//get the url for the suitelet #2; use similar pattern but add more data
var creURL = url.resolveScript({
'scriptId':'customscript_cre_profile_suitelet_exampl',
'deploymentId':'customdeploy_test_cre',
'returnExternalUrl': false
}) + '&profileid=' + CREPROFILE + '&id=' + REC.getValue("id");
//hook point for the button that will be fired client side;
var scr = "require(['N/https'], function(https) {
https.get({'url': '" + buildURL + "'}); //call suitelet #1
window.open('"+creURL+"','_blank'); //call suitelet #2
});";
// log.debug(funcName, scr);
//add button to the form; when clicked, call the scr function
context.form.addButton({
id : "custpage_cre_view_agreement",
label : "Print Retainer",
functionName: scr
})