Hi there,
I'm using the ScriptRunner post-function "Clones an issue and links." I need to create a set of linked issues, but the team wishes to avoid duplicates.
New issues will be created with a summary like:
issue.summary = 'Training for ' + sourceIssue.summary
I wrote the condition below to check linked issue summaries for a match:
def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueLinks = issueLinkManager.getOutwardLinks(issue.getId()) Issue issue = issue String sourceName = issue.getSummary() log.info "Source name is " + sourceName // Check if instance of this issue name already exists !(issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> def linkedIssue = issueLink.destinationObject String issueName = linkedIssue.getSummary() log.info "New issue name is " + issueName issueName == "Training for " + sourceName})
I see the values I expect in the log, but a duplicate issue is created anyway.
I also tried creating a second variable in case I was not comparing apples to apples somehow:
def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueLinks = issueLinkManager.getOutwardLinks(issue.getId()) Issue issue = issue String sourceName = issue.getSummary() log.info "Source name is " + sourceName String newName = "Training for " + sourceName log.info "New name is " + newName // newName returns the string I expect // Check if instance of this issue name already exists !(issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> def linkedIssue = issueLink.destinationObject String issueName = linkedIssue.getSummary() log.info "New issue name is " + issueName issueName == newName})
I can see from the log that I'm definitely finding linked issues with the summary I don't want to duplicate:
/secure/WorkflowUIDispatcher.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] New issue name is Training for test
But it seems finding does not mean actually preventing duplicate issues.
Anyone know what I'm doing wrong?
Thanks!
Try this code to check dublicates:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.link.IssueLink String sourceName = issue.getSummary() log.info "Source name is " + sourceName String newName = "Training for " + sourceName log.info "New name is " + newName // newName returns the string I expect // Check if instance of this issue name already exists boolean isAlreadyExist = false; for(IssueLink issueLink: ComponentAccessor.getIssueLinkManager().getOutwardLinks (issue.id)){ if(newName == issueLink.destinationObject.getSummary()){ isAlreadyExist = true; break; } } if(isAlreadyExist) log.info "isAlreadyExist"
Hey thanks!
Unfortunately, that returns "Condition did not return a boolean, coercing to false."
I've tried declaring a Boolean before as a condition in a workflow, which always returns that same error. I'm no programmer, but still, I'm a little confused about why the result of a Boolean is not a Boolean... (laughing).
I've only ever gotten this to work by doing something like "!(statement to evaluate)".
Trying to figure out how to restate what you have there....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.link.IssueLink String sourceName = issue.getSummary() log.info "Source name is " + sourceName String newName = "Training for " + sourceName log.info "New name is " + newName // newName returns the string I expect // Check if instance of this issue name already exists for(IssueLink issueLink: ComponentAccessor.getIssueLinkManager().getOutwardLinks (issue.id)){ if(newName == issueLink.destinationObject.getSummary()){ return true; } } return false
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aha, that was it!
Except, whatever code is behind this condition seems to create an issue if the result is true, and not if the answer is false, so I just switched the logic, and it is working like this:
for(IssueLink issueLink: ComponentAccessor.getIssueLinkManager().getOutwardLinks (issue.id)){ if(newName == issueLink.destinationObject.getSummary()){ return false; } } return true
Thanks so much for all your help!
THAT wasn't counter-intuitive at all
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.