commonfields:
  id: MarkAsNoteByTag
  version: -1
name: MarkAsNoteByTag
releaseNotes: "Script to mark entries with given tag as notes"
script: |
  entries = demisto.executeCommand('getEntries', {})
  if isError(entries[0]):
      demisto.results({'Type': entryTypes['error'], 'ContentsFormat': formats['text'], 'Contents': 'Unable to retrieve entries'})
  else:
      ids = ''
      for e in entries:
          tags = e.get('Metadata', {}).get('tags')
          if not tags:
              tags = []
          if demisto.getArg('tag') in tags:
              if ids == '':
                  ids = e['Metadata']['id']
              else:
                  ids += ',' + e['Metadata']['id']
      if ids != '':
          demisto.results(demisto.executeCommand('markAsNote', {'entryIDs': ids}))
      else:
          demisto.results({'Type': entryTypes['error'], 'ContentsFormat': formats['text'],
              'Contents': "No entries with '" + demisto.getArg('tag') + "' found"})
type: python
tags:
- Utilities
comment: Mark entries as notes if they are tagged with given tag
enabled: true
args:
- name: tag
  required: true
  default: true
  description: Entries with the given tag will be marked as notes
scripttarget: 0
runonce: false

Mark entries as notes by tag
Mark entries as notes by tag
