Create Form Using Suitelet

How to create a simple form for a new customer in NetSuite account (using Suitelet script) and then redirect to the newly created customer record?

I want to create a suitelet form for a new customer record in Netsuite account using some common APIs. And, after creating the record form will be redirected to that particular customer record page.

In the ‘GET’ part, I used nlapiCreateForm(title) API to create a form named ‘Simple Form’. Then, added some required fields (to create a customer record) in that form by using addField(name, type, label) and added a button to submit the form using addSubmitButton(label) API.

if (request.getMethod() == 'GET') {

       var form = nlapiCreateForm('Simple Form');
        form.addField('company', 'text', 'Company Name');
        form.addField('address','text','Address');
        form.addSubmitButton('Submit');
        response.writePage(form);
    }

In the else part (i mean to say, in ‘POST’ method), all vaules (filled up in the form) will be fetched from those field using getParameter(name) API.

Then, a new record will be generated by using nlapiCreateRecord(type).

All filled up values in that form will be set in the required fields of customer record, according to the internal id of those fields.

setFieldValue(name, value) and setLineItemValue(group, name, linenum, value) APIs is used to set value in customer record fields. Then, nlapiSubmitRecord(record) will submit and commit the new customer record.

After submitting the form, it will be redirected to the new created customer record page by using nlapiSetRedirectURL(type, identifier, id, editmode, parameters)API.

else {

        var compName = request.getParameter('company');
        var compAdd = request.getParameter('address');       

        var newCust = nlapiCreateRecord('customer');
        newCust.setFieldValue('companyname', compName);
        newCust.setLineItemValue('addressbook', 'addr1', 1, compAdd);
        var id = nlapiSubmitRecord(newCust);

        nlapiSetRedirectURL('RECORD','customer',id,null,false);    
}
150 150 Burnignorance | Where Minds Meet And Sparks Fly!