Suitelet Scripts as XML Definitions

You can import suitelet script objects from a target NetSuite account into your SuiteCloud projects for SuiteCloud Development Framework (SDF). Suitelets are extensions of the SuiteScript API that give developers the ability to build custom NetSuite pages and backend logic. Suitelets are server-side scripts that operate in a request-response model. They are invoked by HTTP GET or POST requests to system generated URLs. For more information, see SuiteScript 2.x Suitelet Script Type.

The suitelet script object can be created in a SuiteCloud project and deployed to a target NetSuite account. Suitelet scripts can also be imported from a target NetSuite account into a SuiteCloud project. For information about importing SDF custom objects, files, and scripts from a target NetSuite account into a SuiteCloud project, see Account Component Imports to SuiteCloud Projects.

For information about working with a suitelet script object from your SuiteCloud project, see the following topics:

For additional information about suitelet scripts, see:

Components of a Script Object

There are three components that are required for the script object:

  1. The Scriptid Attribute: Provide a readable scriptid attribute for the script record and scriptdeployment structure by adding an underscore to the default value followed by a meaningful name for the object. The script record’s scriptid attribute must start with a customscript_ prefix and each scriptdeployment structure’s scriptid attribute must start with a customdeploy_ prefix.

  2. The Script Record: Represented in XML by the object. The object contains several elements that define it, including the object name and a reference to the location of the script file.

  3. The Script Deployment Record: Represented in XML by the scriptdeployments structure. A script object may contain multiple script deployments.

Components of a Suitelet Script Object

The following components allow the suitelet script object to work.

  • The Script Record: Represented in XML by the suitelet script object. The object contains several elements that define it, including the name of the suitelet script object, and a reference to the location of the suitelet script file.

    The following example shows a suitelet script object named Suitelet Script Test that references a suitelet script file named Suitelet.js and has the script id customscript_suitelettest.

                    <suitelet scriptid="customscript_suitelettest">
           <name>Suitelet Script Test</name>
    <notifyowner>T</notifyowner>
        <scriptfile>[/SuiteScripts/Suitelet.js]</scriptfile>
        <scriptdeployments>
            <scriptdeployment scriptid="customdeploy_suitelettest">
                <isdeployed>T</isdeployed>
                <loglevel>DEBUG</loglevel>
                <status>TESTING</status>
                <title>SuiteletScriptTest</title>
            </scriptdeployment>
        </scriptdeployments>
        </suitelet> 
    
                  
  • The Script Deployment Record: Represented in XML by the scriptdeployments structure. It is contained within the suitelet script object where you can define certain values such as the title, status and event type for your script deployments.

    The following example shows two scriptdeployments structures with the titles SuiteletScriptTest and SuiteletScriptTest2, and a status value set to TESTING.

                    <suitelet scriptid="customscript_suitelettest">
           <name>Suitelet Script Test</name>
    <notifyowner>T</notifyowner>
        <scriptfile>[/SuiteScripts/Suitelet.js]</scriptfile>
        <scriptdeployments>
            <scriptdeployment scriptid="customdeploy_suitelettest">
                <isdeployed>T</isdeployed>
                <loglevel>DEBUG</loglevel>
                <status>TESTING</status>
                  <title>SuiteletScriptTest</title>
            </scriptdeployment>
        </scriptdeployments>
       </suitelet> 
    
                  

For more information about:

Setting Values for a Script Object

Each script object has a set of values that are required to successfully validate its script record and script deployment record.

The following elements are required to successfully validate your script record:

  • name —Provide a meaningful name for your script record.

  • scriptfile —Reference the appropriate script file. This must be a JavaScript file (.js).

The following element is required to successfully validate your script deployments:

  • status —Provide a value for the status element. The default value is TESTING. The only values accepted for all scripts except scheduled scripts are:

    • RELEASED: The script will run in the accounts of all specified audience members.

    • TESTING: The script will execute for the script owner and specified audience.

    The remaining possible values for the status element are:

    • COMPLETED

    • INPROGRESS

    • INQUEUE

    • NOTSCHEDULED

    • SCHEDULED

Setting Values for a Suitelet Script Object

Provide a readable scriptid attribute for the suitelet script object and scriptdeployment structure by adding an underscore to the default value, followed by a meaningful name for the object. The suitelet script object’s scriptid attribute must start with a “customscript_” prefix and each scriptdeployment structure’s scriptid attribute must start with a “customdeploy_” prefix.

The following elements are required to successfully validate your suitelet script object:

  • name —Provide a meaningful name for your script record.

  • scriptfile —Reference the appropriate script file. This must be a JavaScript file (.js).

The following elements are required to successfully validate your script deployments:

  • title —Provide a meaningful title for your script deployment record.

  • status —Provide a value for the status element. The default value is TESTING. Possible values are:

    • RELEASED: The script will run in the accounts of all specified audience members.

    • TESTING: The script will execute for the script owner and specified audience.

The following element is optional to successfully validate your suitelet script object:

eventtype —This element is optional. You can use the <eventtype> tag in your script deployment record to specify a script execution context at the same time of script deployment. For a suitelet script object, the available values for the <eventtype> tag are GET and POST. If you leave your <eventtype> tag blank, your project will still deploy and only execute the event type or event types that are specified in the suitelet script file referenced in your script deployment record.

Note:

Warning - If you specify an event type, your deployed script will execute only on that specific event regardless of the event types that are specified in your suitelet script file. For example, if you set the value of your event type to GET, your script will be restricted from running on any event other than GET request.

For information about:

Example of a Suitelet Script Object

The following example shows a suitelet script object named Suitelet Script Test that references a suitelet script file named Suitelet.js and has the script id customscript_suitelettest.

              <suitelet scriptid="customscript_suitelettest">
    <name>Suitelet Script Test</name>
<notifyowner>T</notifyowner>
    <scriptfile>[/SuiteScripts/Suitelet.js]</scriptfile>
    <scriptdeployments>
        <scriptdeployment scriptid="customdeploy_suitelettest">
            <isdeployed>T</isdeployed>
            <loglevel>DEBUG</loglevel>
            <status>TESTING</status>
            <eventtype><eventtype>
            <title>SuiteletScriptTest</title>
        </scriptdeployment>
    </scriptdeployments>
    <scriptdeployments>
        <scriptdeployment scriptid="customdeploy_suitelettest2">
            <isdeployed>T</isdeployed>
            <loglevel>DEBUG</loglevel>
            <status>TESTING</status>
            <eventtype><eventtype>
            <title>SuiteletScriptTest2</title>
        </scriptdeployment>
    </scriptdeployments>
</suitelet> 

            

The following example shows a suitelet script file named Suitelet.js that is referenced in the suitelet script object. This sample is of a basic suitelet that shows an empty page with a Hello World header. For information about writing more complex scripts such as suitelets used to create custom pages, forms, lists, assistants and backend suitelets, see SuiteScript 2.x Suitelet Script Type Code Samples.

              /**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define([], function() {
    function onRequest(context) {
        var html = '<html><body><h1>Hello World</h1></body></html>';
        context.response.write(html);
        context.response.setHeader({
            name: 'Custom-Header-Demo',
            value: 'Demo'
        });
    }

    return {
        onRequest: onRequest
    };
}); 

            

Related Topics

General Notices