ResponseTemplate - Scoped, Global
The ResponseTemplate script include provides methods for managing response templates.
Response templates are reusable messages that agents can copy to case or task forms. They provide quick and consistent messages to users and display standard chat response messages to requesters in Agent Chat. This script include requires the Templated Responses plugin (com.sn_templated_snip), which is activated by default, and runs within the sn_templated_snip
namespace.
For additional information on response templates, see Response templates.
ResponseTemplate - ResponseTemplate()
Instantiates a new ResponseTemplate object.
| Name | Type | Description |
|---|---|---|
| None |
new sn_templated_snip.ResponseTemplate().query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, true, "");
ResponseTemplate - query(String tableName, String recordId, String searchTerm, Number limit, Number offset, Boolean includeEvaluatedBody, String errorFormat, Object opts)
Returns all response templates from a specified table that match the passed in query criteria.
| Name | Type | Description |
|---|---|---|
| tableName | String | Name of the table to use to search the sn_templated_snip_note_template table to locate corresponding response templates. For example, incident or sn_hr_core_case. |
| recordId | String | Sys ID of the record to use to render the variables in the response template. |
| searchTerm | String | Optional. Text to use to filter the list of matching response templates. The method performs a CONTAINS search of this text on the name and body fields and a STARTS WITH search on the short name field. For example, if the search term is "crash", the method returns any response template that matches the query criteria and has crash in the name or body or the short name starts with crash. Response templates with exact matches on short name appear first in the return results. All other returned response templates are sorted by name. Default: Return all matching response templates. |
| limit | Number | Optional. Maximum number of response templates to return. Default: 50 |
| offset | Number | Optional. For pagination, the index at which to start the search. Default: 0 |
| includeEvaluatedBody | Boolean | Optional. Flag that indicates whether to render the template variables. Valid values:
Default: false |
| errorFormat | String | Optional. HTML formatting to use for errors. For example:
Default: |
| opts | Object | Optional. Parameters to pass to the sn_templated_snip.response_template extension point. The format and content of these parameters are dependent on the implementation of the extension point. For additional information on extension points, see Using extension points to extend application functionality. |
| Type | Description |
|---|---|
| Object | Array of all templates that match the specified search criteria. Response
templates with exact matches on short name appear first in the return results. All
other returned response templates are sorted by name. Each node in the Array may contain the following parameters:
|
This example shows how to query for response templates associated with the incident table.
query("incident","ef4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");
Successful response:
[
{
"sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
"name": "Incident escalation",
"short_name": "escalation",
"template_body": "<p>Dear ${caller_id.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>"
}
]
Same query with an error response.
query("incident","fe4225a40a0a0b5700d0b8a790747812", "", 0, 0, false, "");
Error response:
[
{
"sys_id": "5fc1d65993003300a9bc1d1e867ffb9c",
"name": "Incident escalation",
"short_name": "escalation",
"template_body": "<p>Dear ${caller.first_name},</p>\r\n<p>Please note that your incident ${number} has been escalated to ${assignment_group}. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>${sys_updated_by}</p>",
"evaluated_response": {
"success": false,
"error": {
"unEvaluatedVariables": "caller.first_name",
"message": "Cannot evaluate following variables: caller.first_name"
},
"evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}
}
]
ResponseTemplate - render(String templateId, String tableName, String recordId, String errorFormat, Object opts)
Renders the HTML body of a specified response template.
During rendering, all variables are resolved using the information from the specified table and record. If variables cannot be resolved, or any other problem occurs during rendering, the method returns an error message in the results.
| Name | Type | Description |
|---|---|---|
| templateId | String | Sys ID of the response template to render. |
| tableName | String | Name of the table to use when rendering the variables on the response template. |
| recordId | String | Sys ID of the record to use when rendering the variables on the response template. This record must be in the table specified by tableName. |
| errorFormat | String | Optional. HTML formatting to use for errors. For example:
Default: |
| opts | Object | Optional. Parameters to pass to the sn_templated_snip.response_template extension point. The format and content of these parameters are dependent on the implementation of the extension point. For additional information on extension points, see Using extension points to extend application functionality. |
| Type | Description |
|---|---|
| Object | Results of the render.
|
This code example shows how to request a rendered response template for the incident table.
render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")
Successful response:
{
"success": true,
"evaluated_body": "<p>Dear Beth,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}
Same render request but returning an error response.
render("5fc1d65993003300a9bc1d1e867ffb9c","incident","ef4225a40a0a0b5700d0b8a790747812", "")
Error response:
{
"success": false,
"error": {
"unEvaluatedVariables": "caller.first_name",
"message": "Cannot evaluate following variables: caller.first_name"
},
"evaluated_body": "<p>Dear <span style='color:#ff0000'>${caller.first_name}</span>,</p>\r\n<p>Please note that your incident INC0000049 has been escalated to Hardware. An agent will be assigned on your case and will keep you updated. If you have more questions please reach out to our team.</p>\r\n<p>Regards,</p>\r\n<p>admin</p>"
}