Start Using Scriptable Cart with SuiteCommerce or SCA

The following steps describe how to start using Scriptable Cart with your SuiteCommerce or SuiteCommerce Advanced (SCA) website:

Note:

Before you can start writing and testing scripts for Scriptable Cart, you need to enable several features in NetSuite. For details, see Set Up Scriptable Cart.

  1. Create a basic script to learn how Scriptable Cart works.

    If you want to verify that the Scriptable Cart functionality is working and see how a simple script works, follow the steps in Write and Test a Basic Script.

  2. Develop several basic custom functions.

    Add the custom functions described in Basic Custom Functions to your script. These custom functions illustrate how to take advantage of the client and user event functions supported by Scriptable Cart.

  3. Create a more complex script.

    Develop the script described in Scriptable Cart Gift Card Example for SuiteCommerce or SCA to enhance the shopping experience with Scriptable Cart.

  4. To learn more about debugging your scripts, see Debugging Scriptable Cart for SuiteCommerce or SCA

Note:

The topics in this section describe how to get started with Scriptable Cart for your SuiteCommerce or SCA website. For detailed information, see Scriptable Cart.

Write and Test a Basic Script

If you want to start with something basic so you know that the functionality is working, you can write and test a simple script.

To write and test a basic script:

  1. Create a folder called scriptablecart in a local directory. In that folder, create a file named examplescriptable.js that contains the following javascript:

                      function debug (message)
    {
      nlapiLogExecution('DEBUG', 'Example Scriptable Cart', message);
    }
    
    function customRecalc ()
    {
      debug('recalc called!')
    } 
    
                    

    The preceding script creates a utility function that sends log messages to the backend and a recalc function that simply sends a log message to communicate that it exists.

  2. Upload the script to NetSuite and create a script record.

    1. In NetSuite, go to Customization > Scripting > Scripts > New.

    2. Click +.

      Note:

      The + (New) option displays when you hover over the area next to the Script File field.

    3. Set the following options:

      • Attach From: Computer

      • Select File: Click Browse to select the script you created in Step 1.

    4. Click Save.

    5. Click Create Script Record.

    6. Choose Client from the list of script types.

    7. On the Script page, enter or set the following:

      • Name: Example Scriptable Cart

      • ID: _example_scriptable_cart

      • Scripts tab, Recalc Function field: customRecalc

      • Deployment tab

        • Applies To: Sales Order

        • Status: Released

        Note:

        Don't forget to click Add.

    8. Click Save.

  3. Test the script as follows:

    1. Go to your Commerce website and either add an item to the cart or change the quantity of an item already in the cart.

      Remember, the recalc function is called when the contents of the cart change therefore these changes should invoke your script.

    2. To check the script execution log for the message generated by your script, go to: Customization > Scripting > Scripts.

    3. Find your script, Example Scriptable Cart, in the list and click View.

    4. In the Execution Log tab, check for the Debug message from the script: recalc called!

Related Topics

Scriptable Cart Fundamentals and Set Up
Basic Custom Functions
Best Practices for Using Scriptable Cart with SuiteCommerce or SCA
Scriptable Cart Gift Card Example for SuiteCommerce or SCA
Debugging Scriptable Cart for SuiteCommerce or SCA

General Notices