We can pass search query as a data source to a template instead of a single record data.
Use the function TemplateRenderer.addQuery(options) for this. This is a part of the N/render module and is available for all server scripts(of the 2.x version).
The parameters require are:
- ‘options.id’ of string type which stores the id of search if options.query is not specified
- ‘options.templateName’ is the name of the template used
- ‘options.query’ is the query and can is required if ‘options.id’ is not specified
The optional parameters are: - ‘options.pageIndex’ stores the page Index as a number
- ‘options.pageSize’ stores page size as a number
This is helpful when data is to be fetched from a search query. Refer the code for more:
//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>${line[‘0@label’]}:${line[0]}\n”
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