Netsuite Tutorials: Suitelet Types in Netsuite.



suitelet in netsuite
Suitelet Type in Netsuite

Hi All,

Suitelet is one of 11 type of script Netsuite supports.Developer can create a custom record and use userevents script in most of cases but if you need a screen which require functionality like data from saved search, need customization while showing data on screen , creation of form using functionality Netsuite does not support as standard etc then use Suitelet Scripts.
Suitelet scripts can be used to show form, process data and also to get/post data. Suitelet can be a starting point of any suite app. Usually company create their own page (in suitelet) and users can set preference, start process etc from this custom screen.

Types of Suitelet:
1. Internal Suitelet
2. External Suitelet

Netsuite provide api to create Suitelet using form, or we can use HTML, CSS etc to show suitelet as we want.

1. Internal Suitelet: Internal Suitelet as a name suggest is for used inside Netsuite, user can use this only after login Netsuite and then clicking on URL/Shortcut for that suitelet. This type of suitelets are mostly used for internal uses, like if we have a custom record and we want to restrict people based on role and don't want then to touch record directly , we can create a suitelet , show fields where they will enter data and submit. Suitelet will process it and create record.
  There can be another example like if you want to make your own Approval screen for PO's or SO's and anyone can use that screen and approve multiple PO's or SO's.
** Please note in 2.0 entry point is onRequest(params) , so developer have to add this entry point and define function .
If you use Netsuite API then it will look something like below:

In Suite Script 1.0:
function yourFirstSuiteletInternal(request, response)
{
      if (request.getMethod() == 'GET' )
      {
        var form = nlapiCreateForm('Simple Form');
        var field = form.addField('custpage_text','text', 'Text');
        form.addSubmitButton('Submit');
        response.writePage( form );
      }
      else
      {
        response.write('write your logic here' );
      }
}

In Suite Script 2.0:
 /**
 *@NApiVersion 2.x
 *@NScriptType Suitelet
 */

// this creates a Suitelet form , add field, and get value on submit.

define(['N/ui/serverWidget'],
    function(ui) {
        function netsuiteGuruSuitelet(context) {
            if (context.request.method === 'GET') {
                var form = ui.createForm({
                    title: Netsuite Guru Form'
                });
                var subject = form.addField({
                    id: 'custpage_text',
                    type: ui.FieldType.TEXT,
                    label: 'Text'
                });
             
                form.addSubmitButton({
                    label: 'Submit'
                });
                context.response.writePage(form);
            } else {
                var request = context.request;
                var mText = request.parameters.custpage_text
        log.debug({
            title: 'mText ',
            details: 'mText' +mText
        });
            }
        }
        return {
            onRequest: netsuiteGuruSuitelet
        };
    });

2. External Suitelet: External suitelet as Name suggest is used for showing some thing outside Netsuite, No login required. User can access suitelet without log in Netsuite, Most of the time either company send these kind of suitelet's URL in Email or provide a link on Website. URL of external suitelet is not easy to remember and Long. if you are using GET and using parameters then keep logic as it should not break limitation of URL for Get.
You can use Netsuite's api to create External Suitelet but it will not compatible to your website, So most people customize , Use CSS , Javascript, and HTML to look same like their Website. One of the Best examples where you can see these suitelets are for RMA, or Contact US, or Registration form.
If you use external Suitelet and using HTML it will look something like this:

In Suite Script 1.0 :
function yourFirstExternalSuitelet(request, response)
{
      if (request.getMethod() == 'GET' )
      {
        var html = '<!DOCTYPE html>';
        html += '<html>';
        //you can add you head section  here and add CSS  and javascripts.
        html += '<body>';

        html += '<form>';
        html += '  First name:<br>';
        html += '  <input type="text" name="firstname">';
        html += '  <br>';
        html += '  Last name:<br>';
        html += '  <input type="text" name="lastname">';
        html += '</form>';

        html += '<p>Note that the form itself is not visible.</p>';

        html += '<p>Also note that the default width of a text input field is 20 characters.</p>';

        html += '</body>';
        html += '</html>';

        response.write( html );
      }

      else
      {
        response.write('none found' );
      }
}

In Suite Script 2.0:


/**
*@NApiVersion 2.x
*@NScriptType Suitelet
*/
//simple htl page using external suitelet 2.0
define('N/search', function(search) {

   function onRequest(params) {
     
       var html = '<!DOCTYPE html>';

        html += '<html>';

        //you can add you head section  here and add CSS  and javascripts.

        html += '<body>';


        html += '<form>';

        html += '  First name:<br>';

        html += '  <input type="text" name="firstname">';

        html += '  <br>';

        html += '  Last name:<br>';

        html += '  <input type="text" name="lastname">';

        html += '</form>';


        html += '<p>Note that the form itself is not visible.</p>';


        html += '<p>Also note that the default width of a text input field is 20 characters.</p>';


        html += '</body>';

        html += '</html>';
      params.response.write({ output: html });
   }
  return {
      onRequest: onRequest
  };
});



**** Client script will only work for suitelets with Netsuite API, if you are using HTML then you have to write all validation in java script under head section of HTML. also please note Single Quote and Double Quote some time cause problem, so if you write code and it is not working properly , check using F12(source code). you might see error in html with Red color.

***** We will add working scripts (which will use email module, search module, etc ) in future in our blog.

How to create Suitelet Script in Netsuite?

Step 1: Save code as javascript file.
Step 2: Go to Customization > Scripting > Scripts > New
Upload screen for Suitelet
Customization > Scripting > Scripts > New

Step 3: Upload javascript file,
            If script file is in 1.0, it will open another screen with options
screen shows options when javscript file is in suite script 1.0
Select Suitelet here

          If script file is in suite script 2.0 , it will open script page automatically with default data populated from script file.Function name autopopulate and disabled on Script Page.
script page when script file is in 2.0
When submitted using 2.0
Step 4: Click Save and deploy

Step 5: Enter Deployment id , select status etc on deployment screen.
Deployment screen for suitelet 2.0
** Checkbox "Available Without Login" define if this is internal suitelet or external suitelet.
In case of external suitelet , 3 url will get populated on screen.
When suitelet is available without login

Step 6: Save deployment.


If you have any question or want to add more then please comment below.

Thanks
Netsuite guru










Comments

  1. Hi, I'm reading your post.
    I want to send an email to a client by netsuite.
    In the email body, I want to put a button to change a checkbox field in a CustomRecord.
    How can I do this? Is it possible?

    Greats !

    ReplyDelete
    Replies
    1. thank for reading, You can download our APP for Android. Right now it is basic but we are upgrading and need people like you to help.

      Ok Coming to solution. Button is email is actually a link, but you can design a way to look it like a button, then write a suitelet which work outside Netsuite and get parameter from URL. check for parameter and search for custom record, and update it.
      If you want to show message you can show message also.
      In you email(I am hoping it will be user event or workflow action) add url with custom record id .
      let me know if you still have question
      #happyNetsuiting

      Delete
  2. Replies
    1. Thanks for your comment, please let us know if you have any suggestion for us. keep sharing.

      Delete
  3. hi i have some requirement Create a form with 3 fields. On submit of that form, send an email to the selected customer. please say me how to do this task

    ReplyDelete
    Replies
    1. Hi ( Your name is not visible)
      You can write after submit user event script , send email using N/email module.
      For Module Read this
      https://netsuiteguru.blogspot.com/2016/12/how-to-send-email-in-suitescript20.html
      For Example( This is in map reduce, you add same in user event)
      https://netsuiteguru.blogspot.com/2019/11/map-reduced-sript-example.html
      Hope this will help you.

      Delete
  4. Hi,
    First of all Thanks for such a good blogger for NetSuite learners very helpful.

    can you help me out that i got a requirement like ,I need a custom button lets say Approve on item screen when it is clicked I need to send item details as a pdf attachment via email and some body with two links like Approve and Reject of item. how can i achieve this and what are the scripts that i need to use to fulfill this.

    ReplyDelete
    Replies
    1. Hi @ashok,
      this is not too tough
      you need below Scripts:
      For Approve Button: User Event ( on load)
      Suitelet : to generate pdf and send via email and return response
      On click of button: Use Client script to call above suitelet and based on response show success /failure message.
      This will take time but not too tough.

      Delete

Post a Comment

Thanks for you message, please join us on Facebook and Linkedin