Create the dataset

Note:

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

In this step, you will create the dataset for the workbook. All workbooks must use a dataset. In a dataset, you combine the fields of a root record type and any joined related record types to create a query.

Tip:

If you are new to the Workbook API and want to learn how to create a simple dataset, see Tutorial: Creating a Dataset Using the Workbook API.

Create a new file in a text editor of your choice. In this file, add the following code to load the N/dataset module:

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

}); 

        

This dataset is created using the Dataset Builder Plug-in. When you use this plug-in, your plug-in implementation script file must include the createDataset entry point. This entry point is triggered when the list of datasets is accessed in the SuiteAnalytics Workbook UI. The script file must return this entry point using Object.freeze(). For more information, see Dataset Builder Plug-in.

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

          return Object.freeze({
    createDataset: function (context) {

    }
}); 

        

Inside this function definition, create two joins. The first one joins the base record type for the dataset (transaction) with the transaction line record type using the transactionlines field. The second one joins the transaction line record type with the transaction accounting line record type using the accountingimpact field.

          var transactionlines = nDataset.createJoin({
    fieldId: 'transactionlines'
})

var accountingimpact = nDataset.createJoin({
    fieldId: 'accountingimpact',
    join: transactionlines
}) 

        

The function you define for the createDataset entry point accepts a context parameter. To save a dataset using the Dataset Builder Plug-in, you create a dataset.Dataset object using dataset.create(options), then assign this object to the context.dataset property.

Add the following code to create a dataset and assign it to the context.dataset property:

          context.dataset = nDataset.create({
    type: 'transaction',
    columns: [  ]
}) 

        

Columns represent the fields on each record type that you want to include in the resulting dataset query. You can use dataset.createColumn(options) to create as many columns as you need. In this tutorial, we create columns for several fields, including transaction line ID, transaction name, date, posting period, and more.

Add the following columns to the dataset using the columns parameter of dataset.create(options):

          columns: [
    nDataset.createColumn({
        fieldId: 'id',
        join: transactionlines,
        alias: 'TranlineID',
        label: 'Tranline ID'
    }),
    nDataset.createColumn({
        fieldId: 'trandisplayname',
        alias: 'Transaction',
        label: 'Transaction'
    }),
    nDataset.createColumn({
        fieldId: 'type',
        alias: 'Type',
        label: 'Type'
    }),
    nDataset.createColumn({
        fieldId: 'trandate',
        alias: 'Date',
        label: 'Date'
    }),
    nDataset.createColumn({
        fieldId: 'entity',
        alias: 'Entity',
        label: 'Entity'
    }),
    nDataset.createColumn({
        fieldId: 'postingperiod',
        alias: 'PostingPeriod',
        label: 'Posting Period'
    }),
    nDataset.createColumn({
        fieldId: 'posting',
        join: accountingimpact,
        alias: 'Posting',
        label: 'Posting'
    }),
    nDataset.createColumn({
        fieldId: 'account',
        join: accountingimpact,
        alias: 'Account',
        label: 'Account'
    }),
    nDataset.createColumn({
        fieldId: 'credit',
        join: accountingimpact,
        alias: 'Credit',
        label: 'Credit'
    }),
    nDataset.createColumn({
        fieldId: 'debit',
        join: accountingimpact,
        alias: 'Debit',
        label: 'Debit'
    })
] 

        

At this point, your dataset script file is complete and should look similar to the full script in the Dataset section of Full scripts.

Related Topics

Prerequisites
Full scripts
Set up the workbook
Create a table view
Create a pivot
Tutorial: Creating a Workbook Using the Workbook API

General Notices