Skip to content

Commit

Permalink
Add sc_req_item and incident ticket types to incident mirroring. (dem…
Browse files Browse the repository at this point in the history
…isto#11396)

* added incident mirroring

* update rn

* solvad conflicts

* Update 2_1_14.md

Co-authored-by: roysagi <50295826+roysagi@users.noreply.github.com>
  • Loading branch information
daryakoval and roysagi committed Feb 14, 2021
1 parent a77432f commit 86f1e4c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,8 +2171,13 @@ def update_remote_system_command(client: Client, args: Dict[str, Any], params: D
if parsed_args.incident_changed:
demisto.debug(f'Incident changed: {parsed_args.incident_changed}')
# Closing sc_type ticket. This ticket type can be closed only when changing the ticket state.
if ticket_type == 'sc_task' and parsed_args.inc_status == IncidentStatus.DONE and params.get('close_ticket'):
if (ticket_type == 'sc_task' or ticket_type == 'sc_req_item')\
and parsed_args.inc_status == IncidentStatus.DONE and params.get('close_ticket'):
parsed_args.data['state'] = '3'
# Closing incident ticket.
if ticket_type == 'incident' and parsed_args.inc_status == IncidentStatus.DONE and params.get('close_ticket'):
parsed_args.data['state'] = '7'

fields = get_ticket_fields(parsed_args.data, ticket_type=ticket_type)
if not params.get('close_ticket'):
fields = {key: val for key, val in fields.items() if key != 'closed_at' and key != 'resolved_at'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ script:
- change_request
- sc_request
- sc_task
- sc_req_item
required: false
secret: false
- default: false
Expand Down
19 changes: 13 additions & 6 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,10 @@ def test_upload_entries_update_remote_system_command(mocker):


def ticket_fields(*args, **kwargs):
state = '7' if kwargs.get('ticket_type') == 'incident' else '3'
assert {'close_notes': 'This is closed', 'closed_at': '2020-10-29T13:19:07.345995+02:00', 'impact': '3',
'priority': '4', 'resolved_at': '2020-10-29T13:19:07.345995+02:00', 'severity': '1 - Low',
'short_description': 'Post parcel', 'sla_due': '0001-01-01T00:00:00Z', 'urgency': '3', 'state': '3',
'short_description': 'Post parcel', 'sla_due': '0001-01-01T00:00:00Z', 'urgency': '3', 'state': state,
'work_start': '0001-01-01T00:00:00Z'} == args[0]

return {'close_notes': 'This is closed', 'closed_at': '2020-10-29T13:19:07.345995+02:00', 'impact': '3',
Expand All @@ -795,27 +796,33 @@ def ticket_fields(*args, **kwargs):


def update_ticket(*args):
state = '7' if 'incident' in args else '3'
return {'short_description': 'Post parcel', 'close_notes': 'This is closed',
'closed_at': '2020-10-29T13:19:07.345995+02:00', 'impact': '3', 'priority': '4',
'resolved_at': '2020-10-29T13:19:07.345995+02:00', 'severity': '1 - High - Low',
'sla_due': '0001-01-01T00:00:00Z', 'state': '3', 'urgency': '3', 'work_start': '0001-01-01T00:00:00Z'}
'sla_due': '0001-01-01T00:00:00Z', 'state': state, 'urgency': '3', 'work_start': '0001-01-01T00:00:00Z'}


def test_update_remote_data_sc_task(mocker):
@pytest.mark.parametrize('ticket_type', ['sc_task', 'sc_req_item', 'incident'])
def test_update_remote_data_sc_task_sc_req_item(mocker, ticket_type):
"""
Given:
- ServiceNow client
- ServiceNow ticket of type sc_task
- ServiceNow ticket of type sc_req_item
- ServiceNow ticket of type incident
When
- running update_remote_system_command.
Then
- The state is changed to 3 (closed) after update.
- The state is changed to 3 (closed) after update for sc_task and sc_req_item.
- The state is changed to 7 (closed) after update for incident.
"""
client = Client(server_url='https://server_url.com/', sc_server_url='sc_server_url', username='username',
password='password', verify=False, fetch_time='fetch_time',
sysparm_query='sysparm_query', sysparm_limit=10, timestamp_field='opened_at',
ticket_type='sc_task', get_attachments=False, incident_name='description')
params = {'ticket_type': 'sc_task', 'close_ticket': True}
ticket_type=ticket_type, get_attachments=False, incident_name='description')
params = {'ticket_type': ticket_type, 'close_ticket': True}
args = {'remoteId': '1234', 'data': TICKET_FIELDS, 'entries': [], 'incidentChanged': True, 'delta': {},
'status': 2}
mocker.patch('ServiceNowv2.get_ticket_fields', side_effect=ticket_fields)
Expand Down
4 changes: 4 additions & 0 deletions Packs/ServiceNow/ReleaseNotes/2_1_14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#### Integrations
##### ServiceNow v2
- Added support for closing ticket of sc_req_item type via the outgoing mirror feature.
2 changes: 1 addition & 1 deletion Packs/ServiceNow/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ServiceNow",
"description": "Use The ServiceNow IT Service Management (ITSM) solution to modernize the way you manage and deliver services to your users.",
"support": "xsoar",
"currentVersion": "2.1.13",
"currentVersion": "2.1.14",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 86f1e4c

Please sign in to comment.