(9) Templates
- Support Ticket Tutorial -
Create a Record for Each Support Ticket
Templates are useful to quickly establish the foundation for a feature. This section will add a new command to the Support Ticket entity to generate an html page or PDF with a summary of the ticket.
1. Prepare a Template
- In Code > Templates click
(+)
- Set
Name of Template
to: Ticket Sheet - Verify that
Template Code Language
is set to: HTML - Verify that
Model Type
is set to: Entity - Set
Model type
to: Entity - Set
Entity
to: Ticket
- Click
Finish
Copy and paste the following:
<html>
<head>
<meta charset="UTF-8">
<style>
table {
border-spacing: unset;
margin: auto;
}
td {
padding: 10px;
border-bottom: 1px solid gray;
}
</style>
</head>
<body>
<table>
<tr>
<td>Title</td>
<td>@Model.Title</td>
</tr>
<tr>
<td>Severity</td>
<td>@Model.TicketSeverity.Name</td>
</tr>
<tr>
<td>Author</td>
<td>@Model.CreatedBy?.Name</td>
</tr>
</table>
</body>
</html>
- Save: Ctrl + S
Optional: The Jetveo Platform can be customized with C# coding in many places. This is good example. To make the Ticket Sheet more detailed, add the following within the lower table:
<tr>
<td>Assigned To </td>
<td>@Model.AssignedTo?.Name</td>
</tr>
<tr>
<td>Answer</td>
<td>@Model.DescriptionOfResolution</td>
</tr>
2. Prepare a Business Command
Choose if you want to generate Ticket Sheet as HTML page or PDF or both. For both we can use the same already created template Ticket Sheet. The following steps are very similar for both.
HTML Page
- In Business > Commands and click
(+)
OR TypeCtrl + Shift + C
and, in the Business section, select Command - Set
Name
to: Create Ticket Sheet - Set
Type
to: Entity command - Set
Result type
to: Document - Set
Entity
to: Ticket
- Click
Finish
Paste the following code:
(ticket, db, ctx) =>
{
var sheetHtml = App.Templates.TicketSheet.Render(ticket);
var sheetBytes = Encoding.UTF8.GetBytes(sheetHtml);
return new DocumentResult("ticket-sheet.html", sheetBytes);
}
- Save:
Ctrl + S
PDF
- In Business > Commands and click
(+)
OR TypeCtrl + Shift + C
and, in the Business section, select Command - Set
Name
to: Create Ticket Sheet PDF - Set
Type
to: Entity command - Set
Result type
to: Document - Set
Entity
to: Ticket
- Click
Finish
Paste the following code:
(ticket, db, ctx) =>
{
var sheetHtml = App.Templates.TicketSheet.Render(ticket);
var sheetBytes = App.Tools.Pdf.GenerateFromHtml(sheetHtml);
return new DocumentResult("ticket-sheet.pdf", sheetBytes);
}
- Save:
Ctrl + S
3. Add Command Action to Ticket Page
- Go to UI > Entity pages and double-click Ticket detail
- In the top part of the Layout Editor, click
Add Action
- Verify that
Type
is set to: Execute entity command - Set
Entity Command
to: Create Ticket Sheet or Create Ticket Sheet PDF
- Click
OK
- Save:
Ctrl + S
Your application will now generate a Ticket Sheet when you click on "Create Ticket Sheet" or "Create Ticket Sheet PDF" button in Ticket detail page.