Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed auto closing tickets in service now #31194

Merged
merged 12 commits into from
Dec 17, 2023
14 changes: 12 additions & 2 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2592,17 +2592,21 @@ def update_remote_system_command(client: Client, args: dict[str, Any], params: d
ticket_type = client.ticket_type
ticket_id = parsed_args.remote_incident_id
closure_case = get_closure_case(params)
demisto.debug(f"closure case= {closure_case}")
is_custom_close = False
close_custom_state = params.get('close_custom_state', None)

demisto.debug(f"state will change to= {parsed_args.data.get('state')}")
if parsed_args.incident_changed:
demisto.debug(f'Incident changed: {parsed_args.incident_changed}')
if parsed_args.inc_status == IncidentStatus.DONE:
demisto.debug('Closing incident by closure case')
if closure_case and ticket_type in {'sc_task', 'sc_req_item', SIR_INCIDENT}:
parsed_args.data['state'] = '3'
# These ticket types are closed by changing their state.
if closure_case == 'closed' and ticket_type == INCIDENT:
parsed_args.data['state'] = '7' # Closing incident ticket.
parsed_args.data['close_code'] = "Closed/Resolved by Caller"
parsed_args.data['close_notes'] = parsed_args.delta.get("closeNotes", "Closed by XSOAR")
elif closure_case == 'resolved' and ticket_type == INCIDENT:
parsed_args.data['state'] = '6' # resolving incident ticket.
if close_custom_state: # Closing by custom state
Expand All @@ -2611,11 +2615,17 @@ def update_remote_system_command(client: Client, args: dict[str, Any], params: d
parsed_args.data['state'] = close_custom_state

fields = get_ticket_fields(parsed_args.data, ticket_type=ticket_type)
demisto.debug(f"all fields= {fields}")
if closure_case:
# Convert the closing state to the right one if the ticket type is not incident in order to close the
# ticket/incident via XSOAR
if ticket_type in {'sc_task', 'sc_req_item', SIR_INCIDENT} and not is_custom_close:
if parsed_args.data.get('state') == '7 - Closed' and not is_custom_close:
demisto.debug(f"fields = {fields}")
fields['state'] = TICKET_TYPE_TO_CLOSED_STATE[ticket_type]
if ticket_type == INCIDENT:
fields['close_code'] = "Closed/Resolved by Caller"
fields['close_notes'] = "Closed by XSOAR"
demisto.debug(f"after fields state = {fields['state']}")
fields = {key: val for key, val in fields.items() if key != 'closed_at' and key != 'resolved_at'}

demisto.debug(f'Sending update request to server {ticket_type}, {ticket_id}, {fields}')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ script:
- contextPath: ServiceNow.Generic.Response
description: Generic response to servicenow api.
type: string
dockerimage: demisto/python3:3.10.13.80014
dockerimage: demisto/python3:3.10.13.83255
isfetch: true
ismappable: true
isremotesyncin: true
Expand Down
46 changes: 32 additions & 14 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,28 +1480,37 @@
update_remote_system_command(client, args, params)


TICKET_FIELDS = {'close_notes': 'This is closed', 'closed_at': '2020-10-29T13:19:07.345995+02:00', 'impact': '3',
TICKET_FIELDS = {'close_notes': 'Closed by XSOAR', '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': '1',
'work_start': '0001-01-01T00:00:00Z'}


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': state,
'work_start': '0001-01-01T00:00:00Z'} == args[0]
fields = {'close_notes': 'Closed by XSOAR', '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',
'work_start': '0001-01-01T00:00:00Z'}
if kwargs.get('ticket_type') == 'incident':
fields['state'] = '7'
fields['close_code'] = 'Closed/Resolved by Caller'
assert fields == args[0]

else:
fields['state'] = '3'
assert fields == args[0]

return {'close_notes': 'This is closed', 'closed_at': '2020-10-29T13:19:07.345995+02:00', 'impact': '3',
return {'close_notes': 'Closed by XSOAR', 'close_code': 'Closed/Resolved by Caller',
'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': '1',
'work_start': '0001-01-01T00:00:00Z'}


def update_ticket(*args):
state = '7' if 'incident' in args else '3'
return {'short_description': 'Post parcel', 'close_notes': 'This is closed',
return {'short_description': 'Post parcel', 'close_notes': 'Closed by XSOAR',
'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': state, 'urgency': '3', 'work_start': '0001-01-01T00:00:00Z'}
Expand Down Expand Up @@ -1916,11 +1925,19 @@


def ticket_fields_mocker(*args, **kwargs):
state = '88' if kwargs.get('ticket_type') == 'incident' else '90'
fields = {'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': state,
'work_start': '0001-01-01T00:00:00Z'}
if kwargs.get('ticket_type') == 'incident':
state = '88'
fields = {'close_notes': 'Closed by XSOAR', 'close_code': 'Closed/Resolved by Caller',
'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': state,
'work_start': '0001-01-01T00:00:00Z'}
else:
state = '90'
fields = {'close_notes': 'Closed by XSOAR', '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': state,
'work_start': '0001-01-01T00:00:00Z'}
assert fields == args[0]
return fields

Expand All @@ -1939,7 +1956,7 @@
get_attachments=False, incident_name='description', ticket_type='incident')
assert client.get_content_type(file_name) == expected


Check failure on line 1959 in Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py.test_update_remote_data_custom_state[case - 1]

AssertionError: assert {'close_notes...ty': '4', ...} == {'close_code'...ct': '3', ...} Omitting 11 identical items, use -vv to show Right contains 1 more item: {'close_code': 'Closed/Resolved by Caller'} Full diff: { - 'close_code': 'Closed/Resolved by Caller', 'close_notes': 'Closed by XSOAR',... ...Full output truncated (11 lines hidden), use '-vv' to show

Check failure on line 1959 in Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2_test.py.test_update_remote_data_custom_state[case - 2]

AssertionError: assert {'close_notes...ty': '4', ...} == {'close_code'...ct': '3', ...} Omitting 11 identical items, use -vv to show Right contains 1 more item: {'close_code': 'Closed/Resolved by Caller'} Full diff: { - 'close_code': 'Closed/Resolved by Caller', 'close_notes': 'Closed by XSOAR',... ...Full output truncated (11 lines hidden), use '-vv' to show
@pytest.mark.parametrize('ticket_type, ticket_state, close_custom_state, result_close_state, update_call_count',
[
# case 1 - SIR ticket closed by custom state
Expand Down Expand Up @@ -1973,14 +1990,15 @@
'close_custom_state': close_custom_state}

TICKET_FIELDS['state'] = ticket_state
TICKET_FIELDS['close_notes'] = 'Closed by XSOAR'
args = {'remoteId': '1234', 'data': TICKET_FIELDS, 'entries': [], 'incidentChanged': True, 'delta': {},
'status': 2}

def update_ticket_mocker(*args):
# Represents only the response of the last call to client.update
# In case the custom state doesn't exist -
# in the first call will return the ticket's state as before (in case2 - '16', case4 - '1')
return {'result': {'short_description': 'Post parcel', 'close_notes': 'This is closed',
return {'result': {'short_description': 'Post parcel', 'close_notes': 'Closed by XSOAR',
'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': result_close_state, 'urgency': '3',
Expand Down
7 changes: 7 additions & 0 deletions Packs/ServiceNow/ReleaseNotes/2_5_47.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### ServiceNow v2
- Updated the Docker image to: *demisto/python3:3.10.13.83255*.

- Fixed an issue with mirror-out functionality where tickets were not being closed properly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Fixed an issue with mirror-out functionality where tickets were not being closed properly.
- Fixed an issue with the outgoing mirroring functionality where newly created tickets were incorrectly closed.

4 changes: 2 additions & 2 deletions 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.5.46",
"currentVersion": "2.5.47",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand All @@ -18,4 +18,4 @@
"marketplacev2",
"xpanse"
]
}
}