You are on page 1of 37

Vancouver API Reference

Vancouver API
Reference
Last updated: January 12, 2024

PDF generated on January 12, 2024


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement
ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in
the United States and/or other countries. Other company and product names may be trademarks of the respective companies with which
they are associated.
Vancouver API Reference

Some examples and graphics depicted herein are provided for


illustration only. No real association or connection to ServiceNow
products or services is intended or should be inferred.
This PDF was created from content on docs.servicenow.com. The web
site is updated frequently. For the most current ServiceNow product
documentation, go to docs.servicenow.com.

Company Headquarters
2225 Lawson Lane
Santa Clara, CA 95054
United States
(408)501-8550

PDF generated on January 12, 2024 2


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Table - Scoped, Global


Creates a Table object to add to a PDF document. Defines the data to
use in each cell and sets styles, margins, and alignment.

This API is part of the ServiceNow PDF Generation Utilities


plugin (com.snc.apppdfgenerator) and is provided within the
sn_pdfgeneratorutils namespace. The plugin is activated by default.

This API is a component used with the Document API to generate a PDF.

Build a Table object using the methods in this class. You can use these
additional classes to add cells, paragraphs, and styles to your table:

Cell API

Create a cell using the Cell API. Then, add the cell to your table using
one of these methods:

• Table.addCell()

• Table.addCellWithStyle()

• Table.addHeaderCell()

• Table.addImageCell()

• Table.addParagraphCell()

• Table.addTextCell()

Paragraph API

Create a paragraph using the Paragraph API. Add the paragraph to a


cell in the table using Cell.addParagraph().

Style API

Set styles, colors, and borders using the Style API. Add the styles to the
table using one of these methods:

• Table.setDefaultStyle()

• Table.setHeaderStyle()

PDF generated on January 12, 2024 3


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

You can then apply the Table object to a PDF document using the
following class and method.

Document API

Use the Document.addTable() method to add your table to a PDF


document. You can use the Document.saveAsAttachment() method to
attach the document to a record.

Table - Table(Boolean ltr, Array columnWidths, Boolean largeTable)

Instantiates a new Table object with text direction, column width, and
layout settings.

Parameters

Name Type Description

Flag that indicates text direction of the


language in the table. For information, see
W3C: Script direction and languages.

ltr Boolean Valid values:

• true: Text direction is left-to-right.

• false: Text direction is right-to-left.

Numbers specifying the width of each column


in a table. Sizes are based proportionally. For
example, var columnWidths = [2, 1, 1];
columnWi is a three-column table with a first column
Array
dths twice as large as the other two.

Default: Each column is equal width.

Flag that indicates whether 100% width and


largeTable Boolean fixed layout are set implicitly.
Valid values:

PDF generated on January 12, 2024 4


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Name Type Description


• true: Table uses 100% width with a fixed
layout. If true, use the complete() method
when all content has been added to
indicate that the table is complete.

• false: Automatic table size.

Default: false

Example

The following example shows how to create a 2-column Table object.

var table = new sn_pdfgeneratorutils.Table(true, [70,200]


, false);

Table – addCell(Cell cell)

Adds a cell element to the table.

Parameters

Name Type Description

cell Cell Cell element to add to the table.

Returns

Type Description

None

Example

This example shows how to create a Table object from the incident table
and add a Number and a Short Description cell to each row.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

PDF generated on January 12, 2024 5


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [70,200]
, false);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

var nParagraph = new sn_pdfgeneratorutils.Paragraph("Numb


er");
var sParagraph = new sn_pdfgeneratorutils.Paragraph("Shor
t Description");

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(nParagraph);
hdrCell2.addParagraph(sParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;

PDF generated on January 12, 2024 6


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var numberParagraph = new sn_pdfgeneratorutils.Paragra


ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCell(numCell);
table.addCell(sdCell);

row = row + 1;

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – addCellWithStyle(Cell cell, Style style)

Adds a cell element with an applied style to the table.

Parameters

Name Type Description

cell Cell Cell object to add to the table.

style Style Style to apply to the cell.

Returns

Type Description

None

PDF generated on January 12, 2024 7


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Example

This example shows how to apply a style to a specified Cell object and
save the document as an attachment to a record.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var cellBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6
,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [70,200]
, false);

var cellStyle = new sn_pdfgeneratorutils.Style;


cellStyle.setBackgroundColor(cellBgColor);
cellStyle.setTextAlignment("text-center");
cellStyle.setBold();
cellStyle.setFontColor(whiteColor);

var nParagraph = new sn_pdfgeneratorutils.Paragraph("Numb


er");
var sParagraph = new sn_pdfgeneratorutils.Paragraph("Shor
t Description");

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(nParagraph);
hdrCell2.addParagraph(sParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

PDF generated on January 12, 2024 8


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;

var numberParagraph = new sn_pdfgeneratorutils.Paragra


ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCellWithStyle(numCell, cellStyle);
table.addCell(sdCell);

row = row + 1;

document.addTable(table);
document.saveAsAttachment("incident", "sys_id", "filename.
pdf");

Table – addHeaderCell(Cell cell)

Adds a header Cell object to the table.

Parameters

Name Type Description

cell Cell Header cell to add to the table.

PDF generated on January 12, 2024 9


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Returns

Type Description

None

Example

This example shows how to add a header cell to a table that contains
a Paragraph object. For more information on Paragraph objects, see the
Paragraph API.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [70,200]
, false);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

var nParagraph = new sn_pdfgeneratorutils.Paragraph("Numb


er");
var sParagraph = new sn_pdfgeneratorutils.Paragraph("Shor
t Description");

PDF generated on January 12, 2024 10


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(nParagraph);
hdrCell2.addParagraph(sParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;

var numberParagraph = new sn_pdfgeneratorutils.Paragra


ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCell(numCell);
table.addCell(sdCell);

row = row + 1;

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – addImageCell(Image image)

Adds a cell that contains an image to the table.

PDF generated on January 12, 2024 11


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

image Image Image object to add to the cell.

Returns

Type Description

None

Example

This example shows how to create a table with two image cells and
attach the document to a record.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [70,200]
, false);

var icon = new sn_pdfgeneratorutils.Image("<sys_id>");


var picture = new sn_pdfgeneratorutils.Image("<sys_id>");

table.addImageCell(icon);
table.addImageCell(picture);

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – addParagraphCell(Paragraph p)

Adds a cell that contains a paragraph to the table.

PDF generated on January 12, 2024 12


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

Paragrap
p Paragraph object to add to the cell.
h

Returns

Type Description

None

Example

This example shows how to create a table with a single cell containing
paragraph content.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

var paragraph = new sn_pdfgeneratorutils.Paragraph("Conte


nt to add to the cell");

table.addParagraphCell(paragraph);

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – addTextCell(String text)

Adds a cell that contains a string to the table.

PDF generated on January 12, 2024 13


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

text String Text to add to the cell.

Returns

Type Description

None

Example

This example shows how to create a table with a single cell containing a
string.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");

document.addTable(table);
document.saveAsAttachment("incident", "record_sys_id", "fi
lename.pdf");

Table – complete()

Indicates that all the intended content has been added to a large table.

Use with the Table.flush() method to add additional content to a table


already added to a document. This method only applies when the
largeTable parameter in the constructor is set to true.

PDF generated on January 12, 2024 14


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

None

Returns

Type Description

None

Example

This example shows how to indicate adding content to a table already


added to a document is complete.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1,2,1,1
], true);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

PDF generated on January 12, 2024 15


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var numberParagraph = new sn_pdfgeneratorutils.Paragraph(


"Number");
var descParagraph = new sn_pdfgeneratorutils.Paragraph("S
hort Description");
var stateParagraph = new sn_pdfgeneratorutils.Paragraph("
State");
var assignedParagraph = new sn_pdfgeneratorutils.Paragrap
h("Assigned to");

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;
var hdrCell3 = new sn_pdfgeneratorutils.Cell;
var hdrCell4 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(numberParagraph);
hdrCell2.addParagraph(descParagraph);
hdrCell3.addParagraph(stateParagraph);
hdrCell4.addParagraph(assignedParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);
table.addHeaderCell(hdrCell3);
table.addHeaderCell(hdrCell4);

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;
var stateCell = new sn_pdfgeneratorutils.Cell;
var assignedCell = new sn_pdfgeneratorutils.Cell;

var numberParagraph = new sn_pdfgeneratorutils.Paragra


ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);
var stateParagraph = new sn_pdfgeneratorutils.Paragrap
h(gr.state);
var assignedParagraph = new sn_pdfgeneratorutils.Parag
raph(gr.assigned_to);

PDF generated on January 12, 2024 16


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);
stateCell.addParagraph(stateParagraph);
assignedCell.addParagraph(assignedParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCell(numCell);
table.addCell(sdCell);
table.addCell(stateCell);
table.addCell(assignedCell);

row = row + 1;

document.addTable(table);
table.addTextCell("A cell added later");
table.flush();
table.complete();
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – donotSplitRowOnPageBreak(Boolean value)

Prevents splitting a row across two pages, when possible.

Parameters

Name Type Description

Flag that indicates whether to split a row across


two pages, or move the entire row onto the
second page. However, this property does not
value Boolean
apply when the row spans more than a single
page.
Valid values:

PDF generated on January 12, 2024 17


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Name Type Description


• true: If the remaining part of a page is not
large enough for the row, adds the entire row
to a new page.

• false: If the remaining part of a page is not


large enough for the row, splits the row across
two pages.

Default: false

Returns

Type Description

None

Example

This example shows how to prevent splitting a row across two pages.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [25,25,2
5,75,400], false);

table.addTextCell("Text to add to the cell");


table.addTextCell("More text to add to the cell");
table.addTextCell("Even more text to add to the cell");
table.addTextCell("Even more text to add to the cell");
table.addTextCell("Even more text to add to the cell");

table.donotSplitRowOnPageBreak(true);

document.addTable(table);
document.saveAsAttachment("incident", "record_sys_id", "fi
lename.pdf");

PDF generated on January 12, 2024 18


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Table – flush()

Adds additional content to a table that is already added to a document.

Use with the Table.complete() method to indicate that you have added
all additional content to the table. This method only applies when the
largeTable parameter in the constructor is set to true.

Parameters

Name Type Description

None

Returns

Type Description

None

Example

This example shows how to add a text cell to a table that is already
added to a document.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1,2,1,1
], true);

PDF generated on January 12, 2024 19


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

var numberParagraph = new sn_pdfgeneratorutils.Paragraph(


"Number");
var descParagraph = new sn_pdfgeneratorutils.Paragraph("S
hort Description");
var stateParagraph = new sn_pdfgeneratorutils.Paragraph("
State");
var assignedParagraph = new sn_pdfgeneratorutils.Paragrap
h("Assigned to");

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;
var hdrCell3 = new sn_pdfgeneratorutils.Cell;
var hdrCell4 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(numberParagraph);
hdrCell2.addParagraph(descParagraph);
hdrCell3.addParagraph(stateParagraph);
hdrCell4.addParagraph(assignedParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);
table.addHeaderCell(hdrCell3);
table.addHeaderCell(hdrCell4);

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;
var stateCell = new sn_pdfgeneratorutils.Cell;
var assignedCell = new sn_pdfgeneratorutils.Cell;

var numberParagraph = new sn_pdfgeneratorutils.Paragra

PDF generated on January 12, 2024 20


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);
var stateParagraph = new sn_pdfgeneratorutils.Paragrap
h(gr.state);
var assignedParagraph = new sn_pdfgeneratorutils.Parag
raph(gr.assigned_to);

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);
stateCell.addParagraph(stateParagraph);
assignedCell.addParagraph(assignedParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCell(numCell);
table.addCell(sdCell);
table.addCell(stateCell);
table.addCell(assignedCell);

row = row + 1;

document.addTable(table);
table.addTextCell("A cell added later");
table.flush();
table.complete();
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – getDefaultStyle()

Returns the default style.

PDF generated on January 12, 2024 21


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

None

Returns

Type Description

Style Default style.

Example

This example shows how to set and then return the default style.

var table = new sn_pdfgeneratorutils.Table(true, [1], fal


se);

var style = new sn_pdfgeneratorutils.Style();

style.setItalic();

table.setDefaultStyle(style);

table.addTextCell("Text to add to the cell");

var defaultStyle = table.getDefaultStyle();

gs.info(defaultStyle);

Table – getHeaderStyle()

Returns the style applied to the table's header.

Parameters

Name Type Description

None

PDF generated on January 12, 2024 22


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Returns

Type Description

Style Style applied to the table's header.

Example

This example shows how to set and return the table's header style.

var table = new sn_pdfgeneratorutils.Table(true, [1,1], f


alse);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

var styleObject = table.getHeaderStyle();

gs.info(styleObject);

Table – setBorder(Number width)

Sets a border of designated width around the outer edges of the table.

PDF generated on January 12, 2024 23


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

Width of the border.


width Number
Unit: Points

Returns

Type Description

None

Example

This example shows how to create a table with two-pixel border and
attach the table to a record.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setBorder(2);

document.addTable(table);
"document.saveAsAttachment("incident", "<record_sys_id>"
, "filename.pdf");

Table – setDefaultbackGroundColor(Color color)

Sets the table's default background color.

PDF generated on January 12, 2024 24


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

Color object used as the default background


color Color
color for the table.

Returns

Type Description

None

Example

This example shows how to set the default background color for the
table.

// declare table by providing width array with automatic


table size
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

var color = new sn_pdfgeneratorutils.Color([0.8,0.8,0.8])


;

table.setDefaultbackGroundColor(color);

table.addTextCell("Text to add to the cell");

Table – setDefaultStyle(Style defaultStyle)

Sets the default style to apply to the table.

Parameters

Name Type Description

defaultStyl
Style Default style to apply to the table.
e

PDF generated on January 12, 2024 25


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Returns

Type Description

None

Example

This example shows how to apply a default style to a table.

var table = new sn_pdfgeneratorutils.Table(true, [1], fal


se);

var style = new sn_pdfgeneratorutils.Style();

style.setItalic();

table.setDefaultStyle(style);

table.addTextCell("Text to add to the cell");

var defaultStyle = table.getDefaultStyle();

gs.info(defaultStyle);

Table – setFixedPosition(Number pageNumber, Number left,


Number bottom, Number width)

Sets the table to a fixed position on the page.

Parameters

Name Type Description

pageNum
Number Number of the page to add the table to.
ber

Number of pixels from the left margin to add


the table.
left Number
Unit: Points

PDF generated on January 12, 2024 26


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Name Type Description

Number of pixels from the bottom margin to


add the table.
bottom Number
Unit: Points

Width of the table.


width Number
Unit: Points

Returns

Type Description

None

Example

This example shows how to reposition the table into the bottom left
corner of the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setFixedPosition(1,36,36,500);

document.addTable(table);
"document.saveAsAttachment("incident", "<record_sys_id>"
, "filename.pdf");

Table – setHeaderStyle(Style headerStyle)

Sets the Style object to apply to the table's header.

PDF generated on January 12, 2024 27


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

headerStyl
Style Style object to apply to the table's header.
e

Returns

Type Description

None

Example

This example shows how to set and return the table's header style.

var table = new sn_pdfgeneratorutils.Table(true, [1,1], f


alse);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

var styleObject = table.getHeaderStyle();

gs.info(styleObject);

PDF generated on January 12, 2024 28


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Table – setHorizontalAlignment(String alignment)

Sets the horizontal alignment of the table.

Parameters

Name Type Description

Alignment for the table.


Valid values:

• center: Align contents to the center.


alignment String
• left: Align contents to the left.

• right: Align contents to the right.

Returns

Type Description

None

Example

This example shows how to create a small table aligned in the center of
the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setWidth(90);
table.setHorizontalAlignment("center");

document.addTable(table);

PDF generated on January 12, 2024 29


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – setMargin(Number margin)

Sets all margins around the table to the same width.

Parameters

Name Type Description

Value of the top, right, bottom, and left


margin Number
margins in points.

Returns

Type Description

None

Example

This example shows how to set a margin for the entire table.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setMargin(3);

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – setMarginBottom(Number margin)

Sets the margin at the bottom of the page.

PDF generated on January 12, 2024 30


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

margin Number Height of the bottom margin in points.

Returns

Type Description

None

Example

This example shows how to set a margin for the bottom of the page to
three points.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

var whiteColor = sn_pdfgeneratorutils.Color([1,1,1]);


var greyColor = sn_pdfgeneratorutils.Color([0.8,0.8,0.8]
);
var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0
.6,0.8]);

// Query Incident
var gr = new GlideRecord("incident");
gr.query();

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [70,200]
, false);

var headerStyle = new sn_pdfgeneratorutils.Style;


headerStyle.setBackgroundColor(headerBgColor);
headerStyle.setTextAlignment("text-center");
headerStyle.setBold();
headerStyle.setFontColor(whiteColor);

table.setHeaderStyle(headerStyle);

PDF generated on January 12, 2024 31


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

var nParagraph = new sn_pdfgeneratorutils.Paragraph("Numb


er");
var sParagraph = new sn_pdfgeneratorutils.Paragraph("Shor
t Description");

var hdrCell1 = new sn_pdfgeneratorutils.Cell;


var hdrCell2 = new sn_pdfgeneratorutils.Cell;

hdrCell1.addParagraph(nParagraph);
hdrCell2.addParagraph(sParagraph);

table.addHeaderCell(hdrCell1);
table.addHeaderCell(hdrCell2);

// set the bottom margin to three points


table.setBottomMargin(3);

var row = 0;

while(gr.next()) {
var numCell = new sn_pdfgeneratorutils.Cell;
var sdCell = new sn_pdfgeneratorutils.Cell;

var numberParagraph = new sn_pdfgeneratorutils.Paragra


ph(gr.number);
var sdParagraph = new sn_pdfgeneratorutils.Paragraph(g
r.short_description);

numCell.addParagraph(numberParagraph);
sdCell.addParagraph(sdParagraph);

if (row % 2 == 1) {
table.setDefaultbackGroundColor(greyColor);
} else {
table.setDefaultbackGroundColor(whiteColor);
}

table.addCell(numCell);
table.addCell(sdCell);

row = row + 1;

PDF generated on January 12, 2024 32


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – setMarginLeft(Number margin)

Sets the margin at the left side of the page.

Parameters

Name Type Description

margin Number Width of the left margin in points.

Returns

Type Description

None

Example

This example shows how to set a margin for the left side of the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setMarginLeft(100);

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

PDF generated on January 12, 2024 33


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Table – setMarginRight(Number margin)

Sets the margin at the right side of the page.

Parameters

Name Type Description

margin Number Width of the right margin in points.

Returns

Type Description

None

Example

This example shows how to set a margin for the left side of the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setMarginRight(100);

document.addTable(table);
"document.saveAsAttachment("incident", "<record_sys_id>"
, "filename.pdf");

Table – setMarginTop(Number margin)

Sets a margin at the top of the page.

PDF generated on January 12, 2024 34


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Parameters

Name Type Description

margin Number Height of the top margin in points.

Returns

Type Description

None

Example

This example shows how to set a margin at the top of the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setMarginTop(100);

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – setWidth(Number width)

Sets the table's total width.

Parameters

Name Type Description

width Number Width of the table.

PDF generated on January 12, 2024 35


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Name Type Description


Unit: Points

Returns

Type Description

None

Example

This example shows how to create a table 90 points wide and attach the
document to a record.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.setWidth(90);
table.setHorizontalAlignment("center");

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

Table – useAllAvailableWidth()

Expands the table to use the entire width available on the page.

Parameters

Name Type Description

None

PDF generated on January 12, 2024 36


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.
Vancouver API Reference

Returns

Type Description

None

Example

This example shows how to create a table that expands to the available
width on the page.

var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");


var document = new sn_pdfgeneratorutils.Document.createDo
cument(pageSize);

// declare table by providing width array and Boolean fo


r large table
var table = new sn_pdfgeneratorutils.Table(true, [1], fal
se);

table.addTextCell("Text to add to the cell");


table.useAllAvailableWidth();

document.addTable(table);
document.saveAsAttachment("incident", "<record_sys_id>",
"filename.pdf");

PDF generated on January 12, 2024 37


©2024 ServiceNow. All rights reserved. Terms of Use Privacy Statement

ServiceNow, the ServiceNow logo, Now, and other ServiceNow marks are trademarks and/or registered trademarks of ServiceNow, Inc., in the
United States and/or other countries. Other company and product names may be trademarks of the respective companies with which they are
associated.

You might also like