ServiceNowQueryIncident
This script is used to wrap the generic query-table command in ServiceNow. You can add fields that you want to use as inputs and outputs from the record as script arguments or in the code and work with the records easily.
python · ServiceNow
Details
| ID | ServiceNowQueryIncident |
|---|---|
| Language | python |
| From Version | 5.0.0 |
| Docker Image | demisto/python3:3.12.13.10116658 |
| Tags | servicenow servicenow v2 |
README
Wraps the generic query-table command in ServiceNow. Fields can be added to use as inputs and outputs from the record as script arguments or in the code and work with the records.
Script Data
| Name | Description |
|---|---|
| Script Type | python |
| Tags | servicenow |
Dependencies
This script uses the following commands and scripts.
- servicenow-query-table
Inputs
| Argument Name | Description |
|---|---|
| id | The system ID of the incident. |
| number | Th number of the incident. |
| assignee | The assignee name of the incident. For example, “John Smith”. |
Outputs
| Path | Description | Type |
|---|---|---|
| ServiceNow.Incident.ID | THe ID of the incident. | string |
| ServiceNow.Incident.Description | The description of the incident. | string |
| ServiceNow.Incident.Number | The number of the incident. | number |
| ServiceNow.Incident.Caller | The caller of the incident. | string |
from CommonServerPython import * def test_get_user(mocker): """ Given: - an incident data from service now command When: - executing get_user function Then: - make sure the incident result key is being retrieved """ from ServiceNowQueryIncident import get_user mocker.patch.object(demisto, "executeCommand") mocker.patch.object(demisto, "get", return_value={"result": "test"}) user = get_user("query") assert user == "test" def test_get_user_id(mocker): """ Given: - an incident sys-id When: - executing get_user_id function Then: - make sure that the incident sys ID is retrieved. """ from ServiceNowQueryIncident import get_user_id mocker.patch.object(demisto, "executeCommand") mocker.patch.object(demisto, "get", return_value={"result": [{"sys_id": "123"}]}) incident_sys_id = get_user_id("user1 user2") assert incident_sys_id == "123" def test_get_username(mocker): """ Given: - an incident with first name and last name When: - executing get_user_name function Then: - make sure that the first name and last name are being returned. """ from ServiceNowQueryIncident import get_user_name mocker.patch.object(demisto, "executeCommand") mocker.patch.object(demisto, "get", return_value={"result": [{"first_name": "first-name", "last_name": "last-name"}]}) result = get_user_name("123") assert result == "first-name last-name" def test_main_flow_success(mocker): """ Given: - result of the 'servicenow-query-table' executed command. When: - running the main flow Then: - make sure the main flow gets executed without errors. """ from ServiceNowQueryIncident import main args_mock = {"number": "INC0021211"} mocked_command_data = {"result": [{"number": "INC0021211", "sys_id": "123", "priority": "1"}]} mocker.patch.object(demisto, "executeCommand") mocker.patch.object(demisto, "args", return_value=args_mock) mocker.patch.object(demisto, "get", return_value=mocked_command_data) result = mocker.patch("demistomock.results") main() assert result.call_args.args[0] == { "Type": 1, "Contents": {"result": [{"number": "INC0021211", "sys_id": "123", "priority": "1"}]}, "ContentsFormat": "json", "ReadableContentsFormat": "markdown", "HumanReadable": "### ServiceNow Incidents\n|ID|Number|Priority|\n|---|---|---|" "\n| 123 | INC0021211 | 1 - Critical |\n", "EntryContext": { "ServiceNow.Incident(val.ID===obj.ID)": [{"Number": "INC0021211", "ID": "123", "Priority": "1 - Critical"}] }, }