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

Fix ServiceNow fetch ticket command on notes without dates #26466

Merged
merged 14 commits into from
May 29, 2023
28 changes: 12 additions & 16 deletions Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
import shutil
Expand Down Expand Up @@ -511,20 +513,16 @@ def split_fields(fields: str = '', delimiter: str = ';') -> dict:

def split_notes(raw_notes, note_type, time_info):
notes: List = []
notes_split = raw_notes.split('\n\n')
retrieved_last_note = False
for note in notes_split:
if not note:
continue
if 'Mirrored from Cortex XSOAR' in note:
if retrieved_last_note: # add to last note only in case the note was not filtered by the time filter
notes[-1]['value'] += '\n\n Mirrored from Cortex XSOAR'
continue
note_info, note_value = note.split('\n', 1)
created_on, created_by = note_info.split(' - ')
# The notes should be in this form:
# '16/05/2023 15:49:56 - John Doe (Additional comments)\nsecond note first line\n\nsecond line\n\nthird
# line\n\n2023-05-10 15:41:38 - פלוני אלמוני (Additional comments)\nfirst note first line\n\nsecond line\n\n
delimiter = '([0-9]{1,4}(?:\/|-)[0-9]{1,2}(?:\/|-)[0-9]{1,4}.*\((?:Additional comments|Work notes)\))'
notes_split = list(filter(None, re.split(delimiter, raw_notes)))
for note_info, note_value in zip(notes_split[::2], notes_split[1::2]):
created_on, _, created_by = note_info.partition(" - ")
created_by = created_by.split(' (')[0]
if not created_on or not created_by:
raise Exception(f'Failed to extract the required information from the following note: {note}')
raise Exception(f'Failed to extract the required information from the following note: {note_info} - {note_value}')

# convert note creation time to UTC
try:
Expand All @@ -535,17 +533,15 @@ def split_notes(raw_notes, note_type, time_info):

if time_info.get('filter') and created_on_UTC < time_info.get('filter'):
# If a time_filter was passed and the note was created before this time, do not return it.
demisto.debug(f'Using time filter: {time_info.get("filter")}. Not including note: {note}.')
retrieved_last_note = False
demisto.debug(f'Using time filter: {time_info.get("filter")}. Not including note: {note_info} - {note_value}.')
continue
note_dict = {
"sys_created_on": created_on_UTC.strftime(DATE_FORMAT),
"value": note_value,
"value": note_value.strip(),
"sys_created_by": created_by,
"element": note_type
}
notes.append(note_dict)
retrieved_last_note = True
return notes


Expand Down
4 changes: 4 additions & 0 deletions Packs/ServiceNow/ReleaseNotes/2_5_24.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#### Integrations
##### ServiceNow v2
Fixed an issue where the ***servicenow-get-ticket-notes*** command would fail on tickets with notes that contain two or more new lines.
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.5.23",
"currentVersion": "2.5.24",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down