Conversation
| 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
We need to continue to support incidents. Beyond just the URL, the actual payload may change as well.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Seems like we can get rid of :table if we don't need it.
There was a problem hiding this comment.
Kept :table here since @table is used to determine whether to hit the Case API or Table API endpoint.
There was a problem hiding this comment.
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.
|
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? |
|
Hey @Bubballoo3 , Here are the steps and configuration details I used to test the ServiceNow API locally for case-based reporting:
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).
YAML config/ondemand.d/support.ymlsupport_ticket: 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! |
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/incidentand attachmenttable_name: 'incident'. This change introduces atableconfiguration key underservicenow_apithat defaults to'incident'for complete backward compatibility.Fixes #5251
Changes Made
@table = config[:table] || 'incident'inServiceNowClient#initialize./api/now/table/#{@table}.table_name: @table.ServiceNowClientTestcovering default fallback (incident) and custom table configuration (sn_customerservice_case).Configuration Example
Administrators can now target custom tables in
config/settings.yml: