TemplateRenderer.addQuery(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Adds a SuiteAnalytics Workbook query to use as the renderer’s data source. You can specify the query in two ways:

  • As a query.Query object (which you create using the N/query Module) using the options.query parameter.

  • By providing the workbook ID of an existing SuiteAnalytics workbook using the options.id paramter.

One of options.query or options.id is required.

This method returns a maximum of 5000 results in the query result set. If a query matches more than 5000 results, you must use options.pageIndex and options.pageSize to retrieve the full set of results.

There is no governance for this method. When the renderer is executed, rendering consumes 10 units for every iteration through the results. If the query is specified using a workbook ID, rendering consumes an additional 5 units before the first iteration through the results.

Returns

void

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/render Module

Parent Object

render.TemplateRenderer

Sibling Object Mambers

TemplateRenderer Object Members

Since

2019.2

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.id

string

required if options.query is not specified

Workbook query ID.

options.pageIndex

number

optional

Page index.

options.pageSize

number

optional

Page size. The minimum value is 5, and the maximum value is 1000.

options.templateName

string

required

Name of the results iterator variable referred to in the template.

options.query

query.Query object

required if options.id is not specified

Workbook query definition.

Errors

Error Code

Error Message

Thrown If

MUTUALLY_EXCLUSIVE_ARGUMENTS

Cannot use mutually exclusive arguments.

Both query and ID parameters are provided.

NEITHER_ARGUMENT_DEFINED

One of the following arguments is mandatory: id, query.

Neither options.id nor options.query are provided.

SSS_MISSING_REQD_ARGUMENT

TemplateRenderer.addQuery: Missing a required argument: options.templateName.

The template name is not specified.

UNABLE_TO_LOAD_QUERY

Unable to load query: invalidId.

The query parameter is provided but the ID is not valid.

WRONG_PARAMETER_TYPE

Wrong parameter type: options.query is expected as query.Query.

The query parameter is provided, but the ID has the incorrect type.

Syntax

Note that TemplateRenderer.addQuery(options) binds the results iterator to a template variable. This iterator provides sequential access to the query results. For random access to search results in FreeMarker, process your search data before rendering, and then pass the processed data to the template using TemplateRenderer.addCustomDataSource(options).

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/render Module Script Samples.

          //Add additional code
...
var search = query.create({
    type: query.Type.TRANSACTION
});
var transactionlines = search.join({
    fieldId: "transactionlines"
});
search.condition = transactionlines.createCondition({
    fieldId: "netamount",
    operator: query.Operator.GREATER,
    values: 1
});
search.columns = [
    transactionlines.createColumn({
        fieldId: "netamount",
        label: "Amount"
    }),
];

// get instance of TemplateRenderer - https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4412065265.html
var renderer = render.create();
renderer.templateContent = "<#list page as line><item>${line['0@label']}:${line[0]}</item>\n</#list>"

renderer.addQuery({
    templateName: "page",
    query: search,
    pageSize: 3, // minimum page size is 5, so result will contain 5 lines instead of 3
    pageIndex: 0,
})
...
// Add additional code 

        

Related Topics

N/render Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices