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
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)
In the next screen, specify the parameters and rules of the transition as required.
Optionally, you can add Conditions or Validators to restrict or enforce the transition per your needs.
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)")
}
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.