ServiceNow Integration

ServiceNow Integration

Connect ServiceNow ITSM to TR-AI: integration user or OAuth client credentials, the incident Business Rule, triage group, and how replies, work notes and resolution work.

Note:TR-AI works on the Incident table. A Business Rule sends new incidents and caller comments to TR-AI; TR-AI answers through the Table API with an integration user you create.

What TR-AI does on an incident

SituationWhat TR-AI does in ServiceNow
Confident answer (auto mode)Posts the answer as an Additional comment (customer visible), then sets State = Resolved with a close code and close notes
Draft (assisted mode or medium confidence)Posts the draft as a Work note and queues it in your TR-AI dashboard for one-click approval
Can't answerPosts a Work note with what it found, optionally an acknowledgement comment, and assigns the incident to your triage group
Caller repliesAnswers the new Additional comment in context — unless the incident is assigned to someone or an agent has commented
Work notes, TR-AI's own commentsIgnored

Step 1 — Create the integration user

  1. 1
    Create a user
    System Security → Users → New. User ID e.g. tr_ai.integration, tick Web service access only, set a password.
  2. 2
    Grant roles
    Add the itil role (read/write incidents). The user must also be able to read sys_journal_field (comments/work notes), sys_user, sys_user_group and sys_choice — grant read ACLs or a custom role if your instance restricts them.
  3. 3
    Optional: create a Triage group
    User Administration → Groups → New, name Triage. Incidents TR-AI can't answer are assigned there (you can choose another group name in TR-AI).

Alternative: OAuth client credentials

On Washington DC or later you can use OAuth instead of a password: System OAuth → Application Registry → New → Create an OAuth API endpoint for external clients. Enable the client_credentials grant (system property glide.oauth.inbound.client.credential.grant_type.enabled = true) and set the OAuth Application User to the integration user above. Enter the client ID and secret in TR-AI.

Step 2 — Enter the credentials in TR-AI

Choose ServiceNow at sign-up (or use Update credentials on the dashboard's ServiceNow setup card) and enter the instance URL (e.g. https://acme.service-now.com) and the username/password or OAuth client. TR-AI reads one incident to verify access — nothing is saved if that fails.

Step 3 — Add the Business Rule

  1. 1
    Create the rule
    System Definition → Business Rules → New. Name TicketResolve AI webhook, Table Incident [incident], tick Advanced.
  2. 2
    When to run
    When = after, tick Insert and Update. No filter conditions — the script decides.
  3. 3
    Paste the script
    Copy the script from your dashboard's ServiceNow setup card — it already contains your webhook URL with its secret key and your integration user — into the Advanced tab, and save.
Business Rule script (your dashboard fills in the URL and user)
(function executeRule(current, previous /*null when async*/) {
    // TicketResolve AI — send new incidents and caller comments to TR-AI.
    var isNew = current.operation() == 'insert';
    var commented = !isNew && current.comments.changes();
    if (!isNew && !commented) return;
    // Never send TR-AI's own comments back.
    if (gs.getUserName() == 'tr_ai.integration') return;
    var body = {
        event: isNew ? 'created' : 'comment',
        sys_id: current.getUniqueValue(),
        number: current.getValue('number'),
        short_description: current.getValue('short_description') || '',
        description: current.getValue('description') || '',
        caller_name: current.caller_id.getDisplayValue(),
        caller_email: current.caller_id.email.toString(),
        caller_user: current.caller_id.user_name.toString(),
        comment: isNew ? '' : current.comments.getJournalEntry(1),
        comment_author: gs.getUserName()
    };
    var r = new sn_ws.RESTMessageV2();
    r.setEndpoint('https://ticketresolve.ai/api/integrations/servicenow/webhook/<trial-id>?key=<your-key>');
    r.setHttpMethod('POST');
    r.setRequestHeader('Content-Type', 'application/json');
    r.setRequestBody(JSON.stringify(body));
    r.setHttpTimeout(10000);
    r.executeAsync();
})(current, previous);
Warning:Keep the ?key= part of the URL. Requests without the right key are rejected. If the key ever leaks, contact support to rotate it and paste the new URL.
Tip:The rule sends only new incidents and changes to Additional comments. It skips comments made by the integration user, and TR-AI ignores its own comments again on its side, so it never answers itself.

Step 4 — Import history and go live

  • TR-AI imports resolved and closed incidents from the selected window. The answer is the last agent Additional comment (or the close notes); work notes are stored as internal context only and never quoted to callers.
  • New accounts start in assisted mode: drafts appear as work notes and in the dashboard for approval. Switch assisted mode off when you trust the answers.
  • Test it: create an incident as a test caller with a question your knowledge base answers, then check the work note / comment.

Resolution details

  • State is set to 6 (Resolved). TR-AI reads your active close codes and uses Solution provided (or Solved (Permanently) on older releases). Close notes contain the reply.
  • Approving a draft from the dashboard posts it as an Additional comment and resolves the incident the same way; rejecting assigns it to the triage group.
  • Delivery failures (for example an expired password) show on the dashboard's integration health, are sent to Slack if configured, and leave a work note with the unsent reply.

Troubleshooting

SymptomCheck
Credential check returns 401Password, "Web service access only" user, or the OAuth Application User
Credential check returns 403The integration user needs the itil role
Follow-ups never answeredRead access to sys_journal_field, and that the incident is not assigned to an agent
Nothing arrives at TR-AIBusiness Rule active, After + Insert/Update, Advanced ticked; outbound HTTP allowed from the instance (System Logs → Outbound HTTP Requests)
Incident not resolvedData policies requiring extra fields on Resolved — TR-AI still posts the comment; check the work note