The script is pretty unremarkable, except that it's called by a wrapper script that processes the "new" argument. The same wrapper is attached to the (correctly working) button, which fills the "new" argument with the field value. The behavior is consistently reproducible. At this point, I'm looking for confirmation: Is it expected behavior that scripts triggered by a field change can't modify linked cases? If so, a documentation update and feature idea would be in order. If not, a bug fix is in order. Of course, if you have a workaround better than "Use a button to trigger the script", that would be great! incident = demisto.incidents()[0]
new_parent_case_id = demisto.args()["parent"]
child_case_id = demisto.args().get("child", "")
if child_case_id == "":
child_case_id = incident.get("id", "Error")
# Remove any existing links on the child (current) case
old_linked_incidents_list = incident.get('linkedIncidents', [])
if old_linked_incidents_list:
old_linked_incidents = ",".join(old_linked_incidents_list)
# This line does nothing when this script is triggered by a field change
# It works fine when this script is triggered by a button
# Removing the "incidentId" argument changes nothing
# Changing the "run as" parameter to DBot changes nothing
demisto.executeCommand("linkIncidents", {"incidentId":child_case_id, "linkedIncidentIDs":old_linked_incidents, "action": "unlink"})
# Create new false positive parent, if requested
if new_parent_case_id == "Create":
parent_name = "PARENT: " + demisto.incidents()[0]['name']
resp = demisto.executeCommand("createNewCase", {
"name": parent_name,
"type": "False Positive Parent",
"severity": "low",
"roles": "##Redacted##"
})
if isError(resp[0]):
demisto.results('Error while creating the new false positive parent case: ' + str(resp))
sys.exit(0)
new_parent_case_id = None
if (resp[0] and resp[0]["EntryContext"] and 'CreatedIncidentID' in resp[0]["EntryContext"] ):
new_parent_case_id = resp[0]["EntryContext"]['CreatedIncidentID']
else:
demisto.results(f'Failed to find the new incident id from create case request')
# Update the False Postive Parent field to show the new parent
# Note that this may trigger a field-change script, so it's important to avoid looping around
# However, the problem with the linked incidents happens even when this branch of code is not executed
resp = demisto.executeCommand('setIncident', {
'falsepositiveparent': "{} {}".format(new_parent_case_id, parent_name)
})
# Link to the False Positive Parent
if new_parent_case_id != "None":
# Link to the parent case
# This line does nothing then this script is triggered by a field change
demisto.executeCommand('linkIncidents', {"incidentId":child_case_id, "linkedIncidentIDs":new_parent_case_id})
# Mark the child case as a stalled false positive
# This line works fine when this script is triggered by a field change
resp = demisto.executeCommand('setIncident', {
'id': child_case_id,
'stalled': True,
'falsepositive': True
})
if isError(resp[0]):
demisto.results('Failed updating existing case with false positive attributes: ' + str(resp))
sys.exit(0)
demisto.results("Attempted to attach child false positive case {} to parent case {}".format(child_case_id, new_parent_case_id)) Here's the wrapper: new_field_value = demisto.args()["new"]
new_parent_case_id = new_field_value.split(" ")[0]
# Execute the update
demisto.executeCommand("AddChildToParent", {"parent":new_parent_case_id})
demisto.results("Attempted to attach child false positive case to parent case {}".format(new_parent_case_id))
... View more