CloseTaskSetContext

Close a task with the closeComplete command, but then also add the "comments" to the incident context.

python · xMatters

Details

IDCloseTaskSetContext
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
TagsUtilities

README

Closes a task with the taskComplete command, then returns the context

Script Data


Name Description
Script Type python
Tags utility

Dependencies


This script uses the following commands and scripts.

  • taskComplete

Inputs


Argument Name Description
entry_id The tag or Task ID to close
context_key The incident context key to add the comments to
comments The comments to be added to the incident context

Outputs


There are no outputs for this script.

import traceback
from typing import Any

import demistomock as demisto
from CommonServerPython import *

""" COMMAND FUNCTION """


def close_task_set_context(args: dict[str, Any]) -> CommandResults:
    entry_id_or_tag = args.get("entry_id")
    context_key = args.get("context_key")
    comments = args.get("comments")
    demisto.executeCommand("taskComplete", {"id": entry_id_or_tag, "comments": comments})

    if not entry_id_or_tag:
        raise ValueError("entry_id not specified")
    if not context_key:
        raise ValueError("context_key not specified")

    result = {context_key: comments}

    return CommandResults(
        outputs_key_field=context_key,
        outputs=result,
    )


""" MAIN FUNCTION """


def main():
    try:
        return_results(close_task_set_context(demisto.args()))

    except Exception as ex:
        demisto.error(traceback.format_exc())  # print the traceback
        return_error(f"Failed to execute close_task_set_context. Error: {ex!s}")


""" ENTRY POINT """


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()