I have a suitelet with a sublist button and I am trying to get the button to execute a function on a custom module. I can not get it to work. I get an error "Cannot call method "receive" of undefined" Any Ideas?
Snippet of code to add button
define(['N/error', 'N/record', 'N/search', 'N/ui/serverWidget','./lib1'],
function(error, record, search, ui, lib1) {
//... some code here
searchSublist.addButton({
id: 'custpage_recievepayment',
label: 'Receive Payment',
functionName: "lib1.receive()"});
}
Snippet of custom Module
define(['N/redirect'],
function(redirect){
function receive(){
var deal = '497774';
var url = redirect.toSuitelet({
scriptId: 'customscript_deal_entry_2_0',
deploymentId: 'customdeploy1',
returnExternalUrl: false,
params: {
prevdeal: url
}
})
}
});
SuiteScript is the NetSuite platform built on JavaScript that enables complete customization and automation of business processes. Using the SuiteScript APIs, core business records and user information can be accessed and manipulated via scripts that are executed at pre-defined events.
SuiteScript 1.0, as the legacy system, was introduced around 2005 and is still used by many businesses, while SuiteScript 2.0 was initially introduced in NetSuite Update 2015.2.
In Visual Studio Code, open the SuiteCloud project that you want to create the SuiteScript file in. Open the Command Palette and enter suitecloud . From the dropdown list, select SuiteCloud: Create SuiteScript File. From the dropdown list, select the type of SuiteScript file type you want to create and press Enter.
To test SuiteScript:Go to Customization > Scripting > Script Deployments. List all script deployments in an Excel spreadsheet to use as a checklist to ensure that you test each one. Test all of your operational SuiteScripts for compatibility and ensure they are working as expected.
I was able to get this to work with out the client script or exporting it to the global object that was suggested. The key was to modify my custom module to return the function I wanted to use on the button and calling the custom module file with form.clientScriptFileId
//suitelet
define(['N/error', 'N/record', 'N/search', 'N/ui/serverWidget'],
function(error, record, search, ui) {
// other code here
form.clientScriptFileId = 78627;//this is the file cabinet internal id of my custom module
var searchSublist = form.addSublist({
id: 'custpage_deals',
type: ui.SublistType.LIST,
label: 'Deals'
})
searchSublist.addButton({
id: 'custpage_receivepayment',
label: 'Receive Payment',
functionName: "receive()"
});
//custom module
define(['N/url','N/error'],
function(url, error) {
return{
receive: function(){
//function code here
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With