GetIndexOfArrayValue

This transformer will get an index of an element from an array. ex:["phishing","Malware"], if we provide "Malware" to array_value argument, will get index as 1.

python · Community Common Scripts

Source

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


import traceback


""" MAIN FUNCTION """


def get_index(json_data, array_val):
    element_index = json_data.index(array_val)
    return element_index


def main():
    try:
        json_data = argToList(demisto.args()["value"])
        array_val = demisto.args()["array_value"]
        res = get_index(json_data, array_val)
        demisto.results(res)
    except Exception as ex:
        demisto.error(traceback.format_exc())  # print the traceback
        return_error(f"Failed to execute BaseScript. Error: {str(ex)}")


""" ENTRY POINT """


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

README

This transformer will get an index of an element from an array.
ex:[“phishing”,”Malware”], if we provide “Malware” to array_value argument, will get index as 1.

Script Data


Name Description
Script Type python3
Cortex XSOAR Version 6.8.0

Inputs


Argument Name Description
value The value is an array of elements
array_value Provide the value from the array

Outputs


There are no outputs for this script.