diff --git a/Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py b/Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py index 892d3852c53c..e219bc78894f 100644 --- a/Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py +++ b/Packs/ServiceNow/Integrations/ServiceNowv2/ServiceNowv2.py @@ -1,3 +1,5 @@ +import re + import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 import shutil @@ -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: @@ -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 diff --git a/Packs/ServiceNow/ReleaseNotes/2_5_24.md b/Packs/ServiceNow/ReleaseNotes/2_5_24.md new file mode 100644 index 000000000000..9020f303d07b --- /dev/null +++ b/Packs/ServiceNow/ReleaseNotes/2_5_24.md @@ -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. diff --git a/Packs/ServiceNow/pack_metadata.json b/Packs/ServiceNow/pack_metadata.json index 5b82d5470641..68c7e94e73ed 100644 --- a/Packs/ServiceNow/pack_metadata.json +++ b/Packs/ServiceNow/pack_metadata.json @@ -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": "",