Set up the workbook

Note:

The content in this help topic applies to SuiteScript 2.x.

In this step, you will create the initial structure for the workbook and load the dataset you created in the previous step. In later steps, you will add elements for a table view and pivot to this structure.

Create a new file in a text editor, and add the following code to load the N/dataset and N/workbook modules:

          define(['N/dataset', 'N/workbook'], function(nDataset,nWorkbook) {

}); 

        

Similar to the dataset you created, this workbook is created using the Workbook Builder Plug-in. When you use this plug-in, your plug-in implementation script file must include the createWorkbook entry point. This entry point is triggered when the list of workbooks is accessed in the SuiteAnalytics Workbook UI. The script file must return this entry point. For more information, see Workbook Builder Plug-in.

Inside the define definition, add the following code for the createWorkbook entry point:

          return {
    createWorkbook: function (context) {

    }
} 

        

Inside this function definition, use dataset.load(options) to load the dataset you created in the previous step. The ID of the dataset is the same ID that you specify when you upload the plug-in implementation script file to NetSuite. In this tutorial, the dataset ID is customscript_transaction.

          var dataset = nDataset.load({
    id: 'customscript_transaction'
}) 

        

We also create a helper object to hold values for sort directions, which will help us when we create pivot axes later in the tutorial. This helper object uses workbook.createSort(options) to create simple workbook.Sort objects representing ascending and descending sorts.

          var SORT = {
    ASCENDING: nWorkbook.createSort({
        ascending: true
    }),
    DESCENDING: nWorkbook.createSort({
        ascending: false
    })
} 

        

At this point, your script file should look similar to the following:

          define(['N/workbook', 'N/dataset'], function(nWorkbook, nDataset){
    return {
        createWorkbook: function (context){
            var dataset = nDataset.load({
                id: 'customscript_transaction'
            })

            var SORT = {
                ASCENDING: nWorkbook.createSort({
                    ascending: true
                }),
                DESCENDING: nWorkbook.createSort({
                    ascending: false
                })
            }
        }
    }
}); 

        

Related Topics

Prerequisites
Full scripts
Create the dataset
Create a table view
Create a pivot
Tutorial: Creating a Workbook Using the Workbook API

General Notices