N/datasetLink Module Script Sample

The following script sample demonstrates how to use the features of the N/datasetLink module.

Load Two Datasets and Link Them

Note:

This sample script uses the require function so you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (a script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

This script sample loads two datasets and links them using a common column (posting period).

In this sample, the id parameters of dataset.load(options) represent the script IDs of plug-in scripts that create datasets using the Dataset Builder Plug-in. For more information, see Workbook Builder Plug-in. If you run this script sample in your account, make sure you use script IDs or saved dataset IDs that are valid in your account.

            /**
 * @NApiVersion 2.x
 */
require(['N/datasetLink', 'N/dataset'], function(datasetLink, dataset) {
    // Load the datasets to link
    var budgetDataset = dataset.load({
        id: 'customscript1772'
    });
    var salesDataset = dataset.load({
        id: 'customscript1773'
    });

    // Create expressions for columns in each dataset
    // The alias parameter value represents the alias set
    // on the associated column in the dataset
    var budgetMachinePeriodExp = budgetDataset.getExpressionFromColumn({
        alias: 'budgetmachineperiod'
    });
    var postingPeriodExp = salesDataset.getExpressionFromColumn({
        alias: 'postingperiod'
    });

    // Link the datasets
    var myDatasetLink = datasetLink.create({
        datasets: [budgetDataset, salesDataset],
        expressions: [[budgetMachinePeriodExp, postingPeriodExp]],
        id: 'myLinkedDatasetId'
    });
}); 

          

General Notices