TemplateRenderer.addCustomDataSource(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

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

N/render Module

Since

2016.1

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.alias

string

required

Data source alias

options.format

render.DataSource

required

Data format

options.data

Object | Document | string

required

Object, document, or string

Syntax
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 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 

        

Related Topics

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

General Notices