TemplateRenderer.addCustomDataSource(options)
Method Description |
Adds XML or JSON as custom data source to an advanced PDF/HTML template. |
Returns |
void |
Supported Script Types |
Server scripts For more information, see SuiteScript 2.x Script Types. |
Governance |
None |
Module |
|
Since |
2016.1 |
Parameters
The options parameter is a JavaScript object.
Parameter |
Type |
Required / Optional |
Description |
---|---|---|---|
|
string |
required |
Data source alias |
|
required |
Data format |
|
|
Object | Document | string |
required |
Object, document, or string |
Syntax
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 renderer = render.create();
var xmlObj = xml.Parser.fromString(xmlString);
var jsonObj = JSON.parse(jsonString);
renderer.templateContent = "${XML.book.title}<br />${XML.book.chapter[1].title}<br />${JSON.book.title}<br/>${JSON.book.chapter[1].title}<br/>${JSON_STR.book.title}<br/>${XML_STR.book.title}";
renderer.addCustomDataSource({
format: render.DataSource.XML_DOC,
alias: "XML",
data: xmlObj
});
renderer.addCustomDataSource({
format: render.DataSource.XML_STRING,
alias: "XML_STR",
data: xmlString
});
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "JSON",
data: jsonObj
});
renderer.addCustomDataSource({
format: render.DataSource.JSON,
alias: "JSON_STR",
data: jsonString
});
var xml = renderer.renderAsString();
...
//Add additional code