Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Reading the parent key of a deleted issue in a ScriptRunner script listener in Jira Cloud

Asimetrix Atlassian
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 5, 2025

I need to update a custom field value in the parent of a recently deleted issue in the Issue Deleted script listener of such deleted issue.

I've tried almost everything but with no success yet.

Thanks,

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Carlos Garcia Navarro
Community Champion
October 5, 2025

Hi @Asimetrix Atlassian ,

Welcome to the Community! Can you  please share more details about the script? What's the custom field in the parent issue that needs to be updated? Does Jira let you edit that field if you try to update it manually? Are you getting any errors?

Asimetrix Atlassian
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 7, 2025

Thanks a lot... I need to update the count of child items of the parent whenever a child is created or deleted.

I could easily make it in the creation, but I can't find a way to access the parent key of a deleted issue (issue.getParentObject() or any other way) as to re-count.

I know how to easily do it via automation rules, but this client wants to use ScriptRunner as much as possible.

Thanks in advance,

Andrea Monico
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 21, 2025

Hi @Asimetrix Atlassian 

as you said, you cannot reference the full issue object for an issue that has been deleted and the trick is to reference directly the parent instead.

The script context gives you access to an issue entity of type java.util.Map, it means the issue data is provided as a JSON payload, essentially a nested map of maps.

You can still access all fields (including the parent key and issue type information) through standard Groovy map notation.

You can then reference the parent without having to go through the deleted issue
def issueToUpdate = Issues.getByKey(parentKey as String)


// ScriptRunner for Jira Cloud (HAPI)
// Updates the custom field "No. of Subtasks" for the parent ticket when a subtask is created or deleted

def fields = issue['fields'] as Map
def issueType = fields['issuetype'] as Map
def isSubtask = issueType['subtask'] as Boolean

logger.info("Is subtask: ${isSubtask}")

// If the issue is a subtask, the parent field will be available
if (isSubtask) {
    def parent = fields['parent'] as Map
    def parentKey = parent['key']
    logger.info("Parent key: ${parentKey}")

    def issueToUpdate = Issues.getByKey(parentKey as String)

    // Count subtasks
    def subTasks = issueToUpdate.getSubTaskObjects()
    def subTaskCount = subTasks?.size() ?: 0

    // Name of the single select list custom field
    def selectFieldName = 'No. of Subtasks'

    if(subTaskCount != issueToUpdate.getCustomFieldValue(selectFieldName)) {

        // The option value must exist in the field configuration (e.g., "0", "1", "2", "3", etc.)
        def optionValue = subTaskCount.toString()

        logger.info("Updating ${selectFieldName} for ${issueToUpdate.key} with option '${optionValue}'")

        // Update the single select list field by setting the matching option
        issueToUpdate.update {
            setCustomFieldValue(selectFieldName, optionValue)
        }
    }

} else {
    logger.info("This issue is not a subtask.")
}


DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events