{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":928,"path":"api-reference/server-api-reference/TableBothAPI.md","title":"Table - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# Table - Scoped, Global\n\nCreates a Table object to add to a PDF document. Defines the data to use in each cell and sets styles, margins, and alignment.\n\nThis 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.\n\nThis API is a component used with the [Document API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DocumentBothAPI.md) to generate a PDF.\n\nBuild a Table object using the methods in this class. You can use these additional classes to add cells, paragraphs, and styles to your table:\n\n-   **[Cell API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CellBothAPI.md)**\n\n    Create a cell using the Cell API. Then, add the cell to your table using one of these methods:\n\n    -   Table.addCell\\(\\)\n    -   Table.addCellWithStyle\\(\\)\n    -   Table.addHeaderCell\\(\\)\n    -   Table.addImageCell\\(\\)\n    -   Table.addParagraphCell\\(\\)\n    -   Table.addTextCell\\(\\)\n-   **[Paragraph API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ParagraphBothAPI.md)**\n\n    Create a paragraph using the Paragraph API. Add the paragraph to a cell in the table using Cell.addParagraph\\(\\).\n\n-   **[Style API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/StyleBothAPI.md)**\n\n    Set styles, colors, and borders using the Style API. Add the styles to the table using one of these methods:\n\n    -   Table.setDefaultStyle\\(\\)\n    -   Table.setHeaderStyle\\(\\)\n\nYou can then apply the Table object to a PDF document using the following class and method.\n\n-   **[Document API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/DocumentBothAPI.md)**\n\n    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.\n\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## Table - Table\\(Boolean ltr, Array columnWidths, Boolean largeTable\\)\n\nInstantiates a new Table object with text direction, column width, and layout settings.\n\n<table id=\"table_twm_hjk_34b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nltr\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates text direction of the language in the table. For information, see [W3C: Script direction and languages](https://www.w3.org/International/questions/qa-scripts.en).\n\n Valid values:\n\n-   true: Text direction is left-to-right.\n-   false: Text direction is right-to-left.\n\n</td></tr><tr><td>\n\ncolumnWidths\n\n</td><td>\n\nArray\n\n</td><td>\n\nNumbers specifying the width of each column in a table. Sizes are based proportionally. For example, `var columnWidths = [2, 1, 1];` is a three-column table with a first column twice as large as the other two.Default: Each column is equal width.\n\n</td></tr><tr><td>\n\nlargeTable\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether 100% width and fixed layout are set implicitly.Valid values:\n\n-   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.\n-   false: Automatic table size.\n\n Default: false\n\n</td></tr></tbody>\n</table>The following example shows how to create a 2-column Table object.\n\n```\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n```\n\n## Table – addCell\\(Cell cell\\)\n\nAdds a cell element to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|cell|[Cell](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CellBothAPI.md)|Cell element to add to the table.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a Table object from the incident table and add a Number and a Short Description cell to each row.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n \nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n \nvar nParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar sParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(nParagraph);\nhdrCell2.addParagraph(sParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n \nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCell(numCell);\n   table.addCell(sdCell);\n \n   row = row + 1;\n \n}\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – addCellWithStyle\\(Cell cell, Style style\\)\n\nAdds a cell element with an applied style to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|cell|[Cell](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CellBothAPI.md)|Cell object to add to the table.|\n|style|[Style](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/StyleBothAPI.md)|Style to apply to the cell.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to apply a style to a specified Cell object and save the document as an attachment to a record.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar cellBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n \nvar cellStyle = new sn_pdfgeneratorutils.Style;\ncellStyle.setBackgroundColor(cellBgColor);\ncellStyle.setTextAlignment(\"text-center\");\ncellStyle.setBold();\ncellStyle.setFontColor(whiteColor);\n \nvar nParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar sParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(nParagraph);\nhdrCell2.addParagraph(sParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n \nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCellWithStyle(numCell, cellStyle);\n   table.addCell(sdCell);\n \n   row = row + 1;\n \n}\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"sys_id\", \"filename.pdf\");\n```\n\n## Table – addHeaderCell\\(Cell cell\\)\n\nAdds a header Cell object to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|cell|[Cell](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/CellBothAPI.md)|Header cell to add to the table.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ParagraphBothAPI.md).\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n \nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n \nvar nParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar sParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(nParagraph);\nhdrCell2.addParagraph(sParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n \nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCell(numCell);\n   table.addCell(sdCell);\n \n   row = row + 1;\n \n}\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – addImageCell\\(Image image\\)\n\nAdds a cell that contains an image to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|image|[Image](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ImageBothAPI.md)|Image object to add to the cell.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table with two image cells and attach the document to a record.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n \nvar icon = new sn_pdfgeneratorutils.Image(\"<sys_id>\");\nvar picture = new sn_pdfgeneratorutils.Image(\"<sys_id>\");\n \ntable.addImageCell(icon);\ntable.addImageCell(picture);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – addParagraphCell\\(Paragraph p\\)\n\nAdds a cell that contains a paragraph to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|p|[Paragraph](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ParagraphBothAPI.md)|Paragraph object to add to the cell.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table with a single cell containing paragraph content.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \nvar paragraph = new sn_pdfgeneratorutils.Paragraph(\"Content to add to the cell\");\n \ntable.addParagraphCell(paragraph);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – addTextCell\\(String text\\)\n\nAdds a cell that contains a string to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|text|String|Text to add to the cell.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table with a single cell containing a string.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"record_sys_id\", \"filename.pdf\");\n```\n\n## Table – complete\\(\\)\n\nIndicates that all the intended content has been added to a large table.\n\nUse 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to indicate adding content to a table already added to a document is complete.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1,2,1,1], true);\n \nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n \nvar numberParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar descParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\nvar stateParagraph = new sn_pdfgeneratorutils.Paragraph(\"State\");\nvar assignedParagraph = new sn_pdfgeneratorutils.Paragraph(\"Assigned to\");\n\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell3 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell4 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(numberParagraph);\nhdrCell2.addParagraph(descParagraph);\nhdrCell3.addParagraph(stateParagraph);\nhdrCell4.addParagraph(assignedParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\ntable.addHeaderCell(hdrCell3);\ntable.addHeaderCell(hdrCell4);\n\nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n   var stateCell = new sn_pdfgeneratorutils.Cell;\n   var assignedCell = new sn_pdfgeneratorutils.Cell;\n\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n   var stateParagraph = new sn_pdfgeneratorutils.Paragraph(gr.state);\n   var assignedParagraph = new sn_pdfgeneratorutils.Paragraph(gr.assigned_to);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n   stateCell.addParagraph(stateParagraph);\n   assignedCell.addParagraph(assignedParagraph);\n\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCell(numCell);\n   table.addCell(sdCell);\n   table.addCell(stateCell);\n   table.addCell(assignedCell);\n \n   row = row + 1;\n \n}\n\ndocument.addTable(table);\ntable.addTextCell(\"A cell added later\");\ntable.flush();\ntable.complete();\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – donotSplitRowOnPageBreak\\(Boolean value\\)\n\nPrevents splitting a row across two pages, when possible.\n\n<table id=\"table_vv5_52h_44b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nvalue\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether to split a row across two pages, or move the entire row onto the second page. However, this property does not apply when the row spans more than a single page.Valid values:\n\n-   true: If the remaining part of a page is not large enough for the row, adds the entire row to a new page.\n-   false: If the remaining part of a page is not large enough for the row, splits the row across two pages.\n\n Default: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to prevent splitting a row across two pages.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [25,25,25,75,400], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.addTextCell(\"More text to add to the cell\");\ntable.addTextCell(\"Even more text to add to the cell\");\ntable.addTextCell(\"Even more text to add to the cell\");\ntable.addTextCell(\"Even more text to add to the cell\");\n\ntable.donotSplitRowOnPageBreak(true);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"record_sys_id\", \"filename.pdf\");\n```\n\n## Table – flush\\(\\)\n\nAdds additional content to a table that is already added to a document.\n\nUse 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.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to add a text cell to a table that is already added to a document.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1,2,1,1], true);\n \nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n \nvar numberParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar descParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\nvar stateParagraph = new sn_pdfgeneratorutils.Paragraph(\"State\");\nvar assignedParagraph = new sn_pdfgeneratorutils.Paragraph(\"Assigned to\");\n\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell3 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell4 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(numberParagraph);\nhdrCell2.addParagraph(descParagraph);\nhdrCell3.addParagraph(stateParagraph);\nhdrCell4.addParagraph(assignedParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\ntable.addHeaderCell(hdrCell3);\ntable.addHeaderCell(hdrCell4);\n\nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n   var stateCell = new sn_pdfgeneratorutils.Cell;\n   var assignedCell = new sn_pdfgeneratorutils.Cell;\n\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n   var stateParagraph = new sn_pdfgeneratorutils.Paragraph(gr.state);\n   var assignedParagraph = new sn_pdfgeneratorutils.Paragraph(gr.assigned_to);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n   stateCell.addParagraph(stateParagraph);\n   assignedCell.addParagraph(assignedParagraph);\n\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCell(numCell);\n   table.addCell(sdCell);\n   table.addCell(stateCell);\n   table.addCell(assignedCell);\n \n   row = row + 1;\n \n}\n\ndocument.addTable(table);\ntable.addTextCell(\"A cell added later\");\ntable.flush();\ntable.complete();\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – getDefaultStyle\\(\\)\n\nReturns the default style.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Style|Default style.|\n\nThis example shows how to set and then return the default style.\n\n```\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n\nvar style = new sn_pdfgeneratorutils.Style();\n\nstyle.setItalic();\n\ntable.setDefaultStyle(style);\n \ntable.addTextCell(\"Text to add to the cell\");\n\nvar defaultStyle = table.getDefaultStyle();\n\ngs.info(defaultStyle);\n```\n\n## Table – getHeaderStyle\\(\\)\n\nReturns the style applied to the table's header.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|Style|Style applied to the table's header.|\n\nThis example shows how to set and return the table's header style.\n\n```\nvar table = new sn_pdfgeneratorutils.Table(true, [1,1], false);\n\nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n\nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n\nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n\nvar styleObject = table.getHeaderStyle();\n\ngs.info(styleObject);\n```\n\n## Table – setBorder\\(Number width\\)\n\nSets a border of designated width around the outer edges of the table.\n\n<table id=\"table_vv5_52h_44b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nwidth\n\n</td><td>\n\nNumber\n\n</td><td>\n\nWidth of the border. Unit: Points\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table with two-pixel border and attach the table to a record.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setBorder(2);\n \ndocument.addTable(table);\n\"document.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setDefaultbackGroundColor\\(Color color\\)\n\nSets the table's default background color.\n\n|Name|Type|Description|\n|----|----|-----------|\n|color|[Color](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/ColorBothAPI.md)|Color object used as the default background color for the table.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set the default background color for the table.\n\n```\n// declare table by providing width array with automatic table size\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n\nvar color = new sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\n\ntable.setDefaultbackGroundColor(color);\n \ntable.addTextCell(\"Text to add to the cell\");\n```\n\n## Table – setDefaultStyle\\(Style defaultStyle\\)\n\nSets the default style to apply to the table.\n\n|Name|Type|Description|\n|----|----|-----------|\n|defaultStyle|Style|Default style to apply to the table.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to apply a default style to a table.\n\n```\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n\nvar style = new sn_pdfgeneratorutils.Style();\n\nstyle.setItalic();\n\ntable.setDefaultStyle(style);\n \ntable.addTextCell(\"Text to add to the cell\");\n\nvar defaultStyle = table.getDefaultStyle();\n\ngs.info(defaultStyle);\n```\n\n## Table – setFixedPosition\\(Number pageNumber, Number left, Number bottom, Number width\\)\n\nSets the table to a fixed position on the page.\n\n<table id=\"table_vv5_52h_44b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\npageNumber\n\n</td><td>\n\nNumber\n\n</td><td>\n\nNumber of the page to add the table to.\n\n</td></tr><tr><td>\n\nleft\n\n</td><td>\n\nNumber\n\n</td><td>\n\nNumber of pixels from the left margin to add the table. Unit: Points\n\n</td></tr><tr><td>\n\nbottom\n\n</td><td>\n\nNumber\n\n</td><td>\n\nNumber of pixels from the bottom margin to add the table. Unit: Points\n\n</td></tr><tr><td>\n\nwidth\n\n</td><td>\n\nNumber\n\n</td><td>\n\nWidth of the table. Unit: Points\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to reposition the table into the bottom left corner of the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setFixedPosition(1,36,36,500);\n \ndocument.addTable(table);\n\"document.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setHeaderStyle\\(Style headerStyle\\)\n\nSets the Style object to apply to the table's header.\n\n|Name|Type|Description|\n|----|----|-----------|\n|headerStyle|[Style](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/StyleBothAPI.md)|Style object to apply to the table's header.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set and return the table's header style.\n\n```\nvar table = new sn_pdfgeneratorutils.Table(true, [1,1], false);\n\nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n\nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n\nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n\nvar styleObject = table.getHeaderStyle();\n\ngs.info(styleObject);\n```\n\n## Table – setHorizontalAlignment\\(String alignment\\)\n\nSets the horizontal alignment of the table.\n\n<table id=\"table_vv5_52h_44b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nalignment\n\n</td><td>\n\nString\n\n</td><td>\n\nAlignment for the table. Valid values:\n\n-   center: Align contents to the center.\n-   left: Align contents to the left.\n-   right: Align contents to the right.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a small table aligned in the center of the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setWidth(90);\ntable.setHorizontalAlignment(\"center\");\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setMargin\\(Number margin\\)\n\nSets all margins around the table to the same width.\n\n|Name|Type|Description|\n|----|----|-----------|\n|margin|Number|Value of the top, right, bottom, and left margins in points.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set a margin for the entire table.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setMargin(3);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setMarginBottom\\(Number margin\\)\n\nSets the margin at the bottom of the page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|margin|Number|Height of the bottom margin in points.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set a margin for the bottom of the page to three points.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \nvar whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);\nvar greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);\nvar headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);\n \n// Query Incident\nvar gr = new GlideRecord(\"incident\");\ngr.query();\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [70,200], false);\n \nvar headerStyle = new sn_pdfgeneratorutils.Style;\nheaderStyle.setBackgroundColor(headerBgColor);\nheaderStyle.setTextAlignment(\"text-center\");\nheaderStyle.setBold();\nheaderStyle.setFontColor(whiteColor);\n \ntable.setHeaderStyle(headerStyle);\n \nvar nParagraph = new sn_pdfgeneratorutils.Paragraph(\"Number\");\nvar sParagraph = new sn_pdfgeneratorutils.Paragraph(\"Short Description\");\n \nvar hdrCell1 = new sn_pdfgeneratorutils.Cell;\nvar hdrCell2 = new sn_pdfgeneratorutils.Cell;\n \nhdrCell1.addParagraph(nParagraph);\nhdrCell2.addParagraph(sParagraph);\n \ntable.addHeaderCell(hdrCell1);\ntable.addHeaderCell(hdrCell2);\n\n// set the bottom margin to three points\ntable.setBottomMargin(3);\n \nvar row = 0;\n \nwhile(gr.next()) {\n   var numCell = new sn_pdfgeneratorutils.Cell;\n   var sdCell = new sn_pdfgeneratorutils.Cell;\n \n   var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);\n   var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);\n  \n   numCell.addParagraph(numberParagraph);\n   sdCell.addParagraph(sdParagraph);\n \n   if (row % 2 == 1) {\n      table.setDefaultbackGroundColor(greyColor);\n   } else {\n      table.setDefaultbackGroundColor(whiteColor);\n   }\n \n   table.addCell(numCell);\n   table.addCell(sdCell);\n \n   row = row + 1;\n \n}\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setMarginLeft\\(Number margin\\)\n\nSets the margin at the left side of the page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|margin|Number|Width of the left margin in points.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set a margin for the left side of the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setMarginLeft(100);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setMarginRight\\(Number margin\\)\n\nSets the margin at the right side of the page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|margin|Number|Width of the right margin in points.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set a margin for the left side of the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setMarginRight(100);\n \ndocument.addTable(table);\n\"document.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setMarginTop\\(Number margin\\)\n\nSets a margin at the top of the page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|margin|Number|Height of the top margin in points.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to set a margin at the top of the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setMarginTop(100);\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – setWidth\\(Number width\\)\n\nSets the table's total width.\n\n<table id=\"table_vv5_52h_44b\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nwidth\n\n</td><td>\n\nNumber\n\n</td><td>\n\nWidth of the table.Unit: Points\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table 90 points wide and attach the document to a record.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.setWidth(90);\ntable.setHorizontalAlignment(\"center\");\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n## Table – useAllAvailableWidth\\(\\)\n\nExpands the table to use the entire width available on the page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThis example shows how to create a table that expands to the available width on the page.\n\n```\nvar pageSize = new sn_pdfgeneratorutils.PdfPage(\"A4\");\nvar document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);\n \n// declare table by providing width array and Boolean for large table\nvar table = new sn_pdfgeneratorutils.Table(true, [1], false);\n \ntable.addTextCell(\"Text to add to the cell\");\ntable.useAllAvailableWidth();\n \ndocument.addTable(table);\ndocument.saveAsAttachment(\"incident\", \"<record_sys_id>\", \"filename.pdf\");\n```\n\n"}}