Skip to content

Support configurable ServiceNow target table (#5251) - #5656

Open
adhati09 wants to merge 4 commits into
masterfrom
5251-servicenow-case-support
Open

adhati09 wants to merge 4 commits into
masterfrom
5251-servicenow-case-support

Conversation

@adhati09

@adhati09 adhati09 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR allows Open OnDemand to deliver support tickets to custom ServiceNow tables (such as Cases / sn_customerservice_case) in addition to standard IT Incidents.

Previously, the ServiceNow client hardcoded /api/now/table/incident and attachment table_name: 'incident'. This change introduces a table configuration key under servicenow_api that defaults to 'incident' for complete backward compatibility.

Fixes #5251

Changes Made

  • Added @table = config[:table] || 'incident' in ServiceNowClient#initialize.
  • Updated table creation API endpoint to /api/now/table/#{@table}.
  • Updated attachment creation payload to pass table_name: @table.
  • Added unit tests in ServiceNowClientTest covering default fallback (incident) and custom table configuration (sn_customerservice_case).

Configuration Example

Administrators can now target custom tables in config/settings.yml:

support_ticket:
  servicenow_api:
    server: "[https://example.service-now.com](https://example.service-now.com)"
    table: "sn_customerservice_case"

response_hash = JSON.parse(incident.body)['result'].symbolize_keys
incident_number = response_hash[:number]
incident_id = response_hash[:sys_id]
ticket = @client["/api/now/table/#{@table}"].post(payload.to_json, content_type: :json)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the API for cases. Not sure where you got this from, but it doesn't appear to be right given the documentation I'm reading.

I suspect you're trusting the AI a little too much. One just told me something similar, but a glance at the actual documentation, now and table are not part of the URL path.

https://www.servicenow.com/docs/r/api-reference/rest-apis/case-api.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching that! Updated the endpoint from the Table API to the ServiceNow Case API (/api/sn_customerservice/case).

response_hash = JSON.parse(incident.body)['result'].symbolize_keys
incident_number = response_hash[:number]
incident_id = response_hash[:sys_id]
ticket = @client["/api/sn_customerservice/case"].post(payload.to_json, content_type: :json)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to continue to support incidents. Beyond just the URL, the actual payload may change as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated create to dynamically route between the Case API (/api/sn_customerservice/case) and Table API (/api/now/table/#{@table}) based on configuration so incident creation continues to work.


UA = 'Open OnDemand ruby ServiceNow Client'
attr_reader :server, :auth_header, :client, :timeout, :verify_ssl
attr_reader :server, :auth_header, :client, :timeout, :verify_ssl, :table

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we can get rid of :table if we don't need it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept :table here since @table is used to determine whether to hit the Case API or Table API endpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better configuration name could be used, maybe record_type that defaults to incident and probably should do so even when something other than ['case', 'incident'] is supplied.

@Bubballoo3

Copy link
Copy Markdown
Contributor

I haven't done any experimenting with the ServiceNow API in development, can you share the steps/configs you used to get this working for OSC?

@adhati09

Copy link
Copy Markdown
Contributor Author

Hey @Bubballoo3 ,

Here are the steps and configuration details I used to test the ServiceNow API locally for case-based reporting:

  1. ServiceNow Instance & Credentials

Used a ServiceNow Personal Developer Instance (PDI) (or OSC dev/sandbox instance) so production data remains untouched.

Verified that the API user account has write/create permissions for the target table (e.g., sn_customerservice_case instead of default incident).

  1. Local Dashboard Configuration
    Added the target table and API credentials to your local ondemand.d configuration (or environment variables):

YAML

config/ondemand.d/support.yml

support_ticket:
widget: "servicenow"
servicenow:
instance: "devXXXXX" # Your dev/sandbox instance subdomain
table: "sn_customerservice_case" # Target table being tested
username: "<dev_api_user>"
password: "<dev_api_password>"
3. Testing & Verification

Start the local Rails server (bin/rails s).

Navigate to the Help -> Report Issue / Contact Support form in the dashboard and submit a test submission.

Open your ServiceNow dev instance in the browser and check the target table list (sn_customerservice_case_list.do) to confirm the case record was generated with the correct fields.

Let me know if you hit any endpoint issues or permission errors while setting up your test instance!

@johrstrom johrstrom assigned johrstrom and unassigned adhati09 Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Awaiting Review

Development

Successfully merging this pull request may close these issues.

Create a case via OnDemand support

4 participants