My suitelet calls a restlet and it's all working fine.
The restlet adds sales order lines to existing sales orders.
I'm adding a work/approval flow and transforming the salesorders into invoices and sending emails on another restlet call.
I was originally making the call to the restlet in the response/on the submit.
I added buttons to the response page and broke out the restlet call into it's own function.
The problem I'm having is that the function is executing on the response / submit even though it is only called from a button.
The button works fine as is when click after the response loads.
Since it's on the suitelet response, I have the functions scripted out.
The structure is like this:
const onRequest
function populateReq() - I populate the request here as a javascript object
function createNewSalesOrderLine() - Here I call the populate request and then the restlet
function transformSalesOrder() - here I create the invoices on another restlet call
function setHeaders() - here I set the headers
if (scriptContext.request.method === 'GET') - here the request if executed
}else{ - response object created from a submit button on the request form
The button is added to the response form
var soBtn = responseform.addButton({
id: "thisBtnId",
label: "Create Sales Order Items",
functionName: createNewSalesOrderLine()
})
Additional info:
1. The function is not called anywhere else.
2. I had the function in the response with the same result. Meaning after the }else{
3. I attempted to create the functions in a client script, but since it's the response, I couldn't figure out a way to get the form and/or sublist which I pull the values from to create the sales order lines.
4. As I was researching this problem, I found that chrome executes the button click event when the response is loaded. I attempted to attach a listener to the button and couldn’t get that to work either. I did find some information saying that the DOM is not accessible in NetSuite, however, I also found some code where a listener was attached to a button. If this is possible, it will fix my problem.
My questions are these:
A) How do I prevent the button click from executing when the response is loaded?
And/or
B) How can I get the form/sublist on the response for the client? I tried passing it in as a parameter from the suitelet to the client script and couldn’t get that to work. The client script did receive parameters, just not the form object or sublist object.
If none of these are possible, I’ll redesign my flow.
Thank you!