Forums

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

ScriptRunner Jira Cloud: Change Subtask

Marcelo Ulloa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2024

Hello, I am creating a script so that when an incident goes to the "Cancelled" state, the subtasks are changed to the same state, I managed to make it work but they were changed with any change of state, so I added an "IF" to validate that the status of the parent issue is ID:7, but it did not succeed, try "if (issueInfo.body.fields.status.id == "7") {" to compare the parent issue to see if it met the condition. What could I use to compare the status of the parent issue "if (XXXXXXX == "7") {"

 

def parentKey = 'SCRIP-116'

def parentIssueInfo = get("/rest/api/2/issue/${parentKey}")
.queryString("fields", "status")
.asObject(Map)

assert parentIssueInfo.status == 200

if (XXXXXXX == "7") {

def jqlQuery = 'parent = "${parentKey}"'
def doneTransitionId = 9362

def allSubTasks = get("/rest/api/2/search")
.queryString("jql", jqlQuery)
.asObject(Map)

assert allSubTasks.status >= 200 && allSubTasks.status <= 300

def subtaskIssues = allSubTasks.body.issues as List<Map>

subtaskIssues.each { subtask ->
def transition = post("/rest/api/2/issue/" + subtask.key + "/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: doneTransitionId]])
.asObject(Map)

assert transition.status >= 200 && transition.status <= 300
}
} else {
logger.info("La incidencia padre no está en el estado deseado para la transición.")
}

 

First of all, thank you

 

Regards

 

1 answer

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 24, 2024 edited

Hi Marcello,

I think your condition needs to be like parentIssueInfo.body.fields.status.statusCategory.id

 

The reason is that the status ID is below a statusCategory property.

The way I found this was to run the rest of the call to get the parent issue on the script console and to look at what the status field structure returned is.

I hope this helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer