Save and run the dataset

Note:

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

When you are done creating your dataset, you can save it and run it. You must save the dataset before you can view it in the SuiteAnalytics Workbook UI. When you run the dataset, you receive a query result set that includes all of the rows in the dataset.

In this step, you will save the dataset and run it to obtain the query result set.

  1. In your script file, save the dataset using Dataset.save(options). To save a dataset, you must provide a name, and you can optionally provide an ID (with the prefix custdataset) and a description. If you do not specify an ID, one is generated automatically. Add the following code after you add dataset columns and conditions in Add components to the initial dataset:

                  tutorialDataset.save({
        name: 'My Tutorial Dataset',
        description: 'This is a tutorial dataset.',
        id: 'custdataset_tutorialDataset'
    }); 
    
                
  2. Run the dataset using Dataset.run(). Add the following code after you save the dataset above:

                  var results = tutorialDataset.run(); 
    
                

    The Dataset.run() method returns a query.ResultSet object (which is located in the N/query module). You can also run the dataset as a paged query using Dataset.runPaged(), which returns a query.PagedData object (also located in the N/query module).

Your final script file should look similar to the following:

          require(['N/dataset'], function(dataset) {
    var tutorialDataset = dataset.create({
        type: 'customer'
    });

    var salesRepJoin = dataset.createJoin({
        fieldId: 'salesrep'
    });
    var transactionJoin = dataset.createJoin({
        fieldId: 'entity',
        source: 'transaction'
    });

    var entityIdColumn = dataset.createColumn({
        fieldId: 'entityid'
    });
    var emailColumn = dataset.createColumn({
        fieldId: 'entityid',
        join: salesRepJoin
    });
    var trandateColumn = dataset.createColumn({
        fieldId: 'trandate',
        join: transactionJoin
    });

    var inactiveColumn = dataset.createColumn({
        fieldId: 'isinactive'
    });
    var inactiveCondition = dataset.createCondition({
        column: inactiveColumn,
        operator: 'IS',
        values: [false]
    });
    var trandateCondition = dataset.createCondition({
        column: trandateColumn,
        operator: 'AFTER',
        values: ['3/3/2020']
    });

    tutorialDataset.columns = [entityIdColumn, emailColumn, trandateColumn];
    tutorialDataset.condition = dataset.createCondition({
        operator: 'AND',
        children: [inactiveCondition, trandateCondition]
    });

    tutorialDataset.save({
        name: 'My Tutorial Dataset',
        description: 'This is a tutorial dataset.',
        id: 'custdataset_tutorialDataset'
    });

    var results = tutorialDataset.run();
}); 

        

Testing Your Solution

Typically, you run scripts in NetSuite by associating the script with an entry point. When the entry point is triggered, the associated script runs. For this tutorial, you can test your solution by using the SuiteScript Debugger. You can access the debugger in your NetSuite account and copy the contents of your script file into the debugger. When you run the script, it creates the dataset that you defined in your script. You can verify that the dataset was created successfully by viewing it in the SuiteAnalytics Workbook UI. For more information about the SuiteScript Debugger, see SuiteScript Debugger.

Related Topics

Prerequisites
Create an initial dataset
Create joins with other record types
Create columns
Create conditions
Add components to the initial dataset
Tutorial: Creating a Dataset Using the Workbook API

General Notices