VicDid
VicDid

Reputation: 175

Setting the request URL of a Suitelet form

I have a form with text fields that I want to send to another server. The problem I am having is that I don't know how I set the request URL. I want to send the contents of the form to another URL and then process the response into Netsuite records. Below is the format of how the code will look. Any ideas on how I'm supposed to set that URL? Should I be using nlapiRequestURL()?

function mainFunction(request, response){
  if (request.getMethod() == 'POST'){
    var form = nlapiCreateForm('Form');
    form.addField('field_one', 'text', 'value 1');
    ...
    ...
    form.addSubmitButton('Submit');
    // on submit send to specified URL
    // response processed
    }   
}

Upvotes: 0

Views: 1760

Answers (2)

erictgrubaugh
erictgrubaugh

Reputation: 8847

By using form.addSubmitButton, whenever that is clicked, NetSuite will POST the request back to the same Suitelet that drew the form. This POST request should contain all of the field values from your Suitelet form.

Since you are already rendering your form when the Suitelet receives a POST request, you'll have to decide how to differentiate between the initial POST to render the form, and the POST from the submit button.

If you are sending a request to a different URL (e.g. another Suitelet, or a web service somewhere), then you are correct that you would use nlapiRequestURL.

Upvotes: 2

Rusty Shackles
Rusty Shackles

Reputation: 2840

If you use addSubmitButton, the Suitelet will use the same URL passing the field values to the same url. If you want to send the data to a different URL you can use addButton and put a custom function that will send the data to that URL.

Upvotes: 2

Related Questions