import datetime import pytz res = demisto.executeCommand("sql-command", {"query":"select MAX(id) from db_table"}) args_json = { "FIRST_NAME":demisto.args().get('FirstName'), "LAST_NAME",demisto.args().get('LastName'), "AGE",demisto.args().get('Age') } last_entry_id = res[0]['Contents'][0]['id'] i = int.(last_entry_id)+1 description = "Demisto incident #{demisto.incidents()[0]['id']}" user = demisto.executeCommand('getUsers', {'current': True})[0]['Contents'][0]['name'] last_modified_dt = str(datetime.datetime.now(pytz.timezone('Asia/Jerusalem'))).split('+')[0] res = demisto.executeCommand("sql-command", {"query":f"select * from db_table where FIRST_NAME='{args_json['FIRST_NAME']}' and LAST_NAME='{args_json['LAST_NAME']}'"}) if res[0]['Contents']: entry_id = res[0]['Contents'][0]['id'] demisto.executeCommand("sql-command", {"query":f"UPDATE db_table SET AGE = '{args_json['AGE']}', last_modified_by = '{user}', last_modified_dt ='{last_modified_dt}', where id='{entry_id}';"}) else: demisto.executeCommand("sql-command", {"query":f"insert into db_table ({i}, {user}, {last_modified_dt}, {description}, {args_json['FIRST_NAME']}, {args_json['LAST_NAME']}, {args_json['AGE']}, {user}, {last_modified_dt});"}) i = i+1