ResponseTemplate - Scoped, Global

  • 릴리스 버전: Australia
  • 업데이트 날짜 2026년 03월 12일
  • 소요 시간: 15분
  • 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.

    표 1. Parameters
    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.

    표 2. Parameters
    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:

    • false: Do not render the template variables. The response contains the message variables.
      For example:
      Please note that your case ${number} has been escalated to ${assignment_group}.
    • true: Renders the template variables and returns evaluated_response in the return results.
      For example:
      Please note that your case INC100001 has been escalated to Facilities.

    Default: false

    errorFormat String Optional. HTML formatting to use for errors.

    For example:

    "<span style='color:#ffff00'>${%s}</span>"

    Default: "<span style='color:#ff0000'>${%s}</span>"

    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.
    표 3. Returns
    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:

    • sys_id: String. Unique identifier of the response template.
    • name: String. Name of the response template.
    • short_name: String. Short name of the response template.
    • body: HTML. Body of the response template.
    • short_name_match: Boolean. Flag that indicates whether an exact match occurred on the short name of the response template.
    • evaluated_response: Array. Results of the template evaluation.
      • success: Boolean. Flag that indicates whether all variables rendered properly.
      • evaluated_body: HTML. Rendered response template body.
      • error: Array. Entry for each evaluation error that occurred.
        • inAccessibleVariables: String. Variables in the response template body that could not be resolved.
        • unEvaluatedVariables: String. Variablesin the response template body that were not evaluated.
        • message: String. Error message.

    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.

    표 4. Parameters
    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:

    "<span style='color:#ffff00'>${%s}</span>"

    Default: "<span style='color:#ff0000'>${%s}</span>"

    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.
    표 5. Returns
    Type Description
    Object Results of the render.
    • success: Flag that indicates whether the render was successful.
    • evaluated_body: String. For success, rendered response template body. For error, response template body which includes both rendered and non-renderable variables.
    • error: Object. Error message if render was unsuccessful.
      • unEvaluatedVariables: Variables that could not be rendered.
      • message: Error message.

    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>"
    }