This article is relevant if you want to dynamically add a button to a form which will execute more than one NetSuite Suitelet.
Background
On our customer records, we set a terms we call “Retainer” . I want to have a button draw on the customer record if a retainer is required so that I can generate a request for retainer fees. However, if no retainer is required, I do not want a button. The amount of the retainer needs to be updated by inspecting the underlying invoice and payment records. Thus, when I click the button, I want to run a custom SuiteLet to calculate a value and then I want to run another SuiteLet to pop up a window to draw the custom PDF. Yes, I can put these two functions in one SuiteLet, but the programs are designed to run independently for other reasons.
SuiteScript 2.0 Draw Button Approach
While I could use workflows to draw buttons, I favor SuiteScript in general as I feel I have maximum capacity over the situation.
Using the BeforeLoad User event, I can test for a situation and add a button. Yet adding a button is insufficient. The button must do something when clicked.
Using our Content Renderer Engine (CRE) , I can produce a pop up window that displays a nicely formatted PDF file. The way to create the CRE SuiteLet is covered elsewhere. But how can we get the button to fire the SuiteLet? In my article, Bind NetSuite SuiteScript Client Side Code in Form View Mode, I offer a technique to lay down some dynamic code that can allow you to hook up a script to a button. But there is an easier way with SuiteScript 2.0.
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 })
Work with Senior NetSuite Professionals
The example was produced by one of our Senior consultants. I appreciate the consultant’s talent and we love to help the NetSuite community get more from their NetSuite investment. If you are strong on NetSuite and would like to work with a small team of passionate professionals that hold high standards for care, let’s have a conversation.
Hi Marty,
How can i call custom plugin,when on click button with out using suitelet is it possible can u please help me.
Hello Brus,
This article tries to help how to get that button to work. We can help you individually. Contact us at https://www.prolecto.com/services/netsuite-care/
Marty
Hi MArty,
In NetSuite, How Do I Print Related Records in Advanced PDF/HTML Template,i used like below,
type
total
${lineitem.type}
${lineitem.total}
can you please help me.
Hi Brus,
This question is off topic. You can send requests for help directly via: https://www.prolecto.com/services/innovations/
Best.
Marty
The resolveScript() method has a params option which will automatically add URL parameters for you, instead of concatenating them manually.
Thank you Eric for the refinement.
Marty
Thank you so much for the article. It helped me in solving the issue so quickly.:)