Status of the linked issue to move in progress when the main issues moves to in progress

Ramesh Penuballi September 5, 2023

Dear Team,

 

I have used the below script in groovy in post condition to modify the linked issue status to move in progress when the main issue moves to in progress.

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.link.IssueLinkManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.issueService

def actionId = 101 // Change this to the desired transition ID
def mainIssueKey = issue.key // Assuming this is within a post-function

def mainIssue = ComponentAccessor.issueManager.getIssueObject(mainIssueKey)
def issueLinkManager = ComponentAccessor.issueLinkManager

if (mainIssue) {

def linkedIssues = ComponentAccessor.issueLinkManager.getLinkCollection(mainIssue, currentUser).getAllIssues()
linkedIssues.each { linkedIssue ->
def transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue.id, actionId, new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (!transitionResult.isValid()) {
log.warn"successfull"
}
} else {
log.warn"unsuccessfull"
}
}
The above script modify the linked issues to in progress when its  main issue moved to in progress successfully.
But I am looking for the script to modify linked issue status to in progress which is of the linked issue type "contains". I tried to add  like below code to the above but it is not working.
if(!linkedIssue){
List<IssueLink> outwardLinks = issueLinkManager.getInwardLinks(issue.getId())
.stream()
.filter({ linkName == "contains" })
.collect(Collectors.toList())
if (outwardLinks.size() > 0) {
linkedIssue = outwardLinks.get(0).destinationObject
}
}
Any ideas to achieve the my purpose.?
Thanks and Regards,
Ramesh

1 answer

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2023

HI @Ramesh Penuballi 

 

You can use 

 

 ComponentAccessor.issueLinkManager.getIssueLinks(<LINKTypeID>).collect{it.getSourceObject()}

 

Depending on the direction of the link you may have to use getDestinationObject()

 

Regards

Ramesh Penuballi September 5, 2023

Hi Bonniec,

 

Thanks for the quick response, I have added the link type id in the provided line and added the line in the below code.

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.link.IssueLinkManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueService = ComponentAccessor.issueService

def actionId = 101 // Change this to the desired transition ID
def mainIssueKey = issue.key // Assuming this is within a post-function

def mainIssue = ComponentAccessor.issueManager.getIssueObject(mainIssueKey)
def issueLinkManager = ComponentAccessor.issueLinkManager

if (mainIssue) {
def linkedIssues = ComponentAccessor.issueLinkManager.getIssueLinks(10720).collect{it.getSourceObject()}
linkedIssues.each { linkedIssue ->
def transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue.id, actionId, new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (!transitionResult.isValid()) {
log.warn"successfull"
}
} else {
log.warn"unsuccessfull"
}
}
}
But the transition of the main issue went to hunger state and getting timed out error.

Communications Breakdown

The call to the Jira server did not complete within the timeout period. We are unsure of the result of this operation.

Close this dialog and press refresh in your browser

 

Kindly help me if the place of the provided line is correct or any other modifications required.

 

Thanks and Regards,

Ramesh 

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 5, 2023

Can you add logs to figure out what's going wrong ?

You can try with getDestinationObject. I would add a condition to check if the issue is not the "main" one.

 

Regards

Ramesh Penuballi September 6, 2023

Hi Bonniec,

We have noticed that the script has modified the statuses (On Hold,Dev Complete,Funnel) of multiple projects at the backend in our Jira instance even though we have added the script as custom script in post condition of single project.

Not sure why the  postcondition script  of single  project will cause the modification of the statuses in multiple projects.

Kindly help if you have seen such scenarios in the past.

 

Regards,

Ramesh 

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2023

If you want to have it updating linked issue from a project only, you have to add a if statement to check if the issue is from the expected project.

if(linkedIssue.getProjectObject().getKey() == "ABC"){

//code to transition issue

}

Suggest an answer

Log in or Sign up to answer