MarkAsNoteByTag

Mark entries as notes if they are tagged with given tag.

python · Common Scripts

Details

IDMarkAsNoteByTag
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10404775
TagsUtility

README

Marks entries as notes if they are tagged with a given tag.

Script Data


Name Description
Script Type python
Tags Utility

Inputs


Argument Name Description
tag The entries with the given tag will be marked as notes.

Outputs


There are no outputs for this script.

import demistomock as demisto  # noqa: F401
from CommonServerPython import *  # noqa: F401


def mark_as_note(entries):
    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",
                }
            )


def main():
    entries = demisto.executeCommand("getEntries", {})
    mark_as_note(entries)


if __name__ in ("__main__", "__builtin__", "builtins"):  # pragma: no cover
    main()