Skip to content

Commit fcaec81

Browse files
authored
Scripted rest api retrieve incident (#53)
* Add Scripted REST API for Incident Data Retrieval This commit implements a new Scripted REST API in ServiceNow to allow external applications to retrieve specific incident data based on query parameters. Key Features: - API Endpoint: `/api/incident/retrieve` - Supports query parameters such as `sys_id` and `state` to filter incidents. Script Logic: - Utilizes GlideRecord to query the `incident` table. - If `sys_id` is provided, retrieves the specific incident; otherwise, queries based on the `state`. Response Formatting: - The response is structured in JSON format, providing incident details like `sys_id`, `short_description`, and `state`. Testing: - Instructions for testing the API and documentation for developers on how to use it have been included. * Rename scripted_rest_api_incident_retrieve.js to Scripted Rest API Retrieve Incident.js This commit implements a new Scripted REST API in ServiceNow to allow external applications to retrieve specific incident data based on query parameters.
1 parent 8454dc8 commit fcaec81

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Prompt: Develop a Scripted REST API in ServiceNow to retrieve specific incident data based on query parameters. This API should allow external applications to access incident details in a structured format.
2+
3+
Structure: Outline the steps for creating the API, including endpoint definitions, input parameters, and response formatting.
4+
5+
Expected Output:
6+
7+
Define API Endpoint:
8+
9+
Specify the endpoint (e.g., /api/incident/retrieve).
10+
List accepted query parameters (e.g., sys_id, state).
11+
12+
Script Logic:
13+
Provide a script to query incidents based on parameters.
14+
15+
Example:
16+
var gr = new GlideRecord('incident');
17+
if (current.sys_id) {
18+
gr.get(current.sys_id);
19+
} else {
20+
gr.addQuery('state', current.state);
21+
gr.query();
22+
}
23+
24+
Response Formatting:
25+
Format the response in JSON.
26+
Example:
27+
var response = {};
28+
response.incidents = [];
29+
while (gr.next()) {
30+
response.incidents.push({
31+
sys_id: gr.sys_id,
32+
short_description: gr.short_description,
33+
state: gr.state
34+
});
35+
}
36+
return new sn_ws.Response(response);
37+
Testing and Documentation:
38+
39+
Include instructions for testing the API.
40+
Provide documentation for developers on how to use the API.

0 commit comments

Comments
 (0)