getInputData(inputContext)

Description

Marks the start of the script’s execution. The purpose of the input stage is to generate the input data.

Runs when the getInputData entry point is triggered. This entry point is required.

For information about the context object provided to this entry point, see inputContext.

Note:

If getInputData() returns a data structure with a non-string value, it's converted to a JSON string with JSON.stringify() before being stored.

Returns

Array | Object | File | Query | Dataset | Search | object reference (file, suiteql, query, search)

In simple scenarios, you can return a plain Array or a plain Object.

                    return ["a", "b", "c"]
return { a: 10, b: 20 } 

                  

Often, data comes from a query. In such case, return a SuiteQL object reference.

                    return {
    type: 'suiteql',
    query: 'SELECT id, email FROM Employee WHERE currency = ?',
    params: [currency]
}
// Then, in map phase, call JSON.parse(context.value).values
// to get [123, "john@example.com"] 

                  

Alternatively, you can return Query / Search objects.

                    return query.create(...)
return search.create(...) 

                  

If the query / search exists, simply return a Query / Search object reference. There's no need to load anything.

                    return { type: 'query', id: 123 }
return { type: 'search', id: 123 } 

                  

Another common source of data are files. Map will be called for each line of the file.

                    return file.load(...)
return { type: 'file', id: 123 }
return { type: 'file', path: '/SuiteScripts/data/names.txt' }  // absolute path required
// Then, in map phase, context.key is the line number (starting with 0)
// and context.value is the line itself. 

                  
Note:

The file cannot contain empty lines.

Datasets are supported as well.

                    return dataset.load(...) 

                  

Since

2015.2

Parameters

Parameter

Type

Required / Optional

Description

inputContext

Object

Required

Object that contains:

  • An indication of whether the current invocation of this method represents a restart

  • An Object that represents the input data

For a description of each property in this object, see inputContext Object Members.

Errors

If this function throws an error, the job moves to the summarize(summaryContext) function. The serialized error is encapsulated in the inputSummary.error property.

Syntax

The following code snippet shows the syntax for this member. It's not a functional example. For a complete script example, see SuiteScript 2.x Map/Reduce Script Code Samples.

            // Add additional code
...
function getInputData {
{

    // Reference a saved search that returns a list of NetSuite records that 
    // require processing - for example, sales orders that are pending fulfillment. 

    return {
        type: 'search',
        id: 1234
    }; 
}
...
// Add additional code 

          

Related Topics

General Notices