Forums

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

Change linked issue status when the custom field value updated [ScriptRunner]

Vasanth Kumar Makam August 16, 2018 edited

Hi,

I am trying to change the linked issue status (issue type=build) to "Completed" when the custom field (Build) value change to "In Use" in parent issue. Also, if  custom field (Build) value is not "In Use" then the linked issue status(issue type=build) should be "open".

I believe , this can be done through Script runner listeners.

Please let me know if anyone can help on this.

 

Thanks

Vas

 

1 answer

0 votes
Gundlupet Sreenidhi
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.
August 17, 2018

This is easy to accomplish using the Jira Suite Utilities plugin and you can avoid any scripting.

If you have the JSU plugin, then at the Post-function of your transition choose the option of Linked Transition (JSU)

vasanth1.png

 

In the next screen, specify the parameters and rules of the transition as required. 

vasanth 2.png

 

Optionally, you can add Conditions or Validators to restrict or enforce the transition per your needs.

vasanth 3.png

 

However, if you do not have the JSU plugin, try the following: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

def issueService = ComponentAccessor.getIssueService()

//change linkType to the link type you use
def linkType = ["linkage"]

// 6.x validateTransition wants a User, so we have to use getDirectoryUser()
// 7.x validateTransition wants an ApplicationUser, so remove the .getDirectoryUser() after we upgrade
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser()
def linkMgr = ComponentAccessor.getIssueLinkManager()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
Issue myissue = issue
log.info "Current Issue ID: "+myissue

//here customfield_10200 is the id of the custom field.
//identify the id of your custom field and replace as necessary
CustomField build= customFieldManager.getCustomFieldObject("customfield_10200")
String buildvalue = myissue.getCustomFieldValue(build) as String
log.info "BUILD Value :"+buildvalue

if(buildvalue=="In Use"){
// Loop through the links
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def destIssue = link.getDestinationObject()

// Does the name of the link match "linkage" ?
if (linkType.contains(link.issueLinkType.name)) {
def destStatusObject = destIssue.getStatusObject()

// Prepare the input for the transition
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
setComment("Auto Transitioning")
setSkipScreenCheck(true)
}

// Validate transitioning the linked issue to "Completed"
//update the transition id for your transition - I have used 251
def validationResult = issueService.validateTransition(user, destIssue.id, 251, issueInputParameters)
if (validationResult.isValid()) {
// Perform the transition
def issueResult = issueService.transition(user, validationResult)
if (! issueResult.isValid()) {
log.warn("Failed to transition task ${destIssue.key}, errors: ${issueResult.errorCollection}")
}
} else {
log.warn("Could not transition task ${destIssue.key}, errors: ${validationResult.errorCollection}")
}
}else {
log.warn("Skipping link: ${link.issueLinkType.name} ${destIssue.key} (wrong type)")
}
}
}else{
//Do not change status - remains Open
log.warn("Skipping link: ${link.issueLinkType.name} ${destIssue.key} ${destStatusObject.name} (wrong status)")
}
Omprakash Thamsetty
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.
August 27, 2019

@Gundlupet Sreenidhi  I am not getting any returns for validationResult.

def validationResult = issueService.validateTransition(user, destIssue.id, 251, issueInputParameters)

Do you have any idea what was wrong?

Thanks,

Om.

Suggest an answer

Log in or Sign up to answer