Forums

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

Can someone help rectify why does the statuses won't change?

Hadas Hamerovv
Contributor
October 22, 2021

Hi,
I wish to update linked issues whenever the 'parent' issue is transitioned but can figure out how to do that. (it is not really parent issue but linked issue to several other).

I checked the code (without the put call) and it does retrieve the issue keys. I do get however errors when the put function is there

here is my code: (below is the second one as I thought maybe my approach is wrong and I have to use transitionID)

```

def issueKey = 'AKD-452' //issue.key
def newStatusId = '10005'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

// Find the linked issues
def linkedIssuesKey = result.body.fields.issuelinks.inwardIssue.key
def length = linkedIssuesKey.size()
for (i in 0..<length) {
def fields = get("/rest/agile/1.0/issue/${linkedIssuesKey[i]}")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
.fields as Map
def submit = put("/rest/api/2/issue/${linkedIssuesKey[i]}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields:[
Status: newStatusId
]
])
.asString()
return submit
if (result.status == 204)

{ return 'Success' }

else {
return "${submit.status}: ${submit.body}"
}

}

```

I thought maybe I have to use the transition id so tried this code too:

```

I also tried this code but I get error responses

def issueKey = 'AKD-452' //issue.key
def newTransitionId = '10005'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

// Find the linked issues
def linkedIssuesKey = result.body.fields.issuelinks.inwardIssue.key
def length = linkedIssuesKey.size()
for (i in 0..<length) {
def submit = post("/rest/api/2/issue/${linkedIssuesKey[i]}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: newTransitionId]])
.asObject(Map)

// Log out the issues transitioned or which failed to be transitioned
if (submit.status == 204) {
logger.info("Transition ${newTransitionId} performed for the ${linkedIssuesKey[i]} issue")
} else {
logger.warn("Failed to perform the transition ${newTransitionId} on the ${linkedIssuesKey[i]} issue. ${submit.status}: ${submit.body}")
}

// Collect the success status by issue key to show them as part of the script return value
[(linkedIssuesKey[0]): (submit.status == 204)]
"Status by issue key (transitioned?): ${linkedIssuesKey[i]}"
}

```

 

2 answers

1 accepted

1 vote
Answer accepted
Hadas Hamerovv
Contributor
October 24, 2021

OK, so had many issues with the code:

1. It's not a put request but should be a post request.

2. you must have the 'looped' flag stated.

3. On the way we could shorten the code and use a better for loop statement.

def issueKey = 'enter issue key here' //issue.key
def transitionID = 'enter transition id'
def newStatus = 'On Staging'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)


// Find the linked issues
def linkedIssuesKey = result.body.fields.issuelinks.inwardIssue.key

for (value in linkedIssuesKey) {

// The rest call to transition the issue
def transitionIssue = post("/rest/api/3/issue/$value/transitions")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([transition: [
id: "$transitionID",
looped: false
]
]
)
.asObject(Map)

}

return 200 

 Thanks @Bill Sheboy for spending your time investigating this. I truly appreciate it.

0 votes
Bill Sheboy
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.
October 22, 2021

Hi @Hadas Hamerovv 

You note getting errors with the PUT; what errors are you seeing?  Knowing that will help the community to offer you ideas.

Also, I note in your example using Transition ID that you are passing the status ID for it.  Is that a typo?  If not, please identify and use the transition ID instead, which you may find with this call: https://docs.atlassian.com/software/jira/docs/api/REST/1000.824.0/#api/2/issue-getTransitions

 

Kind regards,
Bill

Hadas Hamerovv
Contributor
October 22, 2021

Hi Bill,

Trying to reply, this website did not allow me. It says I have to wait as I have posted similar things. Guess I have to wait although I did not post elsewhere nothing.

Hadas Hamerovv
Contributor
October 22, 2021

Anyhow, when removing the put request altogether I receive all the linked issues as a list.

When I try the put transition request I get:

POST /rest/api/2/issue/AKD-469/transitions asObject Request Duration: 162ms

POST request to /rest/api/2/issue/AKD-469/transitions returned an error code: status: 400 - Bad Request

body: {errorMessages=[Can't move (AKD-469). You might not have permission, or the issue is missing required information. If you keep having this problem, contact your Jira Administrator.], errors={}}

When I try the put status request I get:

PUT /rest/api/2/issue/AKD-469?overrideScreenSecurity=true asString Request Duration: 984ms

PUT request to /rest/api/2/issue/AKD-469?overrideScreenSecurity=true returned an error code: status: 403 - Forbidden

body: {"errorMessages":["Connect app users with a\”admin\" permission and Forge app users with the \"manage:jira-configuration\" scope can override screen security."],"errors":{}}

Bill Sheboy
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.
October 22, 2021

That seems like something is not passing/using your intended permissions.  I have not used Forge for calling the REST API yet, so you may want to search this community or the dev community to diagnose that error: https://community.developer.atlassian.com/

Suggest an answer

Log in or Sign up to answer