How can we check if the 'parent' issue of a duplicate linkedIssue is not a duplicate of another?

Thanks to what Henning and Jamie have helped here: https://answers.atlassian.com/questions/139592, I know how to validate if the current issue has a duplicate link to another one (called parent)

Now, on top of that, I need add an additional checking that the parent that user has specified for this link should NOT be a duplicate of another parent. 

This sounds easy since I thought I could just get the Id of the parent issue of the link and check its own OutwardLinks to see if any of them is also Duplicate, something like this:

linkCnt = 0
 
request = webwork.action.ActionContext.getRequest()
if (request) {
    // check for new duplicates link
    linktype = request.getParameter('issuelinks-linktype')
    linkedIssue = request.getParameter('issuelinks-issues')
    
    if (linktype == 'duplicates' && linkedIssue)
    {   //----- This is the additional checking
        if(! issueLinkManager.getOutwardLinks(linkedIssue.getId())*.issueLinkType.name.contains('Duplicate') )
	    	linkCnt = 1
    }
}
 
// check for existing duplicates link
if ( issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate') ) linkCnt += 1
 
// Transition requires at least one duplicates link
(linkCnt>=1)

 

But this doesn't work correctly. I guess that it's because of  

linkedIssue.getId()

doesn't give me the correct Id of the parent (destination) issue of the link.

What is the correct function to use here to make this works?

Thanks

Hung

3 answers

1 accepted

linkedIssue is a String, so it doesn't have an id property that you can retrieve. Therefore you will need to replace linkedIssue.getId() with this:

issueManager.getIssueObject(linkedIssue).id

On the other hand, request.getParameter('issuelinks-issues') will only return the first of the issues specified in the parameter, so it might be good to use the following and then iterate over the list of linked issues:

request.getParameterValues('issuelinks-issues')

Hope that helped.

Hi Alejo,

Thank you for the tips.

With this update, I got a different error. Now it says:

built-in script:com.onresolve.scriptrunner.canned.jira.workflow.validators.SimpleScriptedValidator groovy.lang.MissingPropertyException: No such property: issueManager for class: Script9

 

It seemed that I have to import certain module to use this.

I had tried to put an import

import com.atlassian.jira.issue.IssueManager

 

at the top, but it seemed to be the same.

Any advice on this?

Ok, I figured out finally that to use issueManager, we have to explicitly import several packages: Here is the final code that I got which works correctly as I expected, in case someone want to do the same thing

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
linkCnt = 0
 
request = webwork.action.ActionContext.getRequest()
if (request) {
    // check for new duplicates link
    linktype = request.getParameter('issuelinks-linktype')
    linkedIssue = request.getParameter('issuelinks-issues')
    log.debug("linked issue: " + linkedIssue)
    
    if (linktype == 'duplicates' && linkedIssue)
{
       // validate that the parent bug of this link does not have any duplicate link
       if (!issueLinkManager.getOutwardLinks(issueManager.getIssueObject(linkedIssue).id)*.issueLinkType.name.contains('Duplicate'))
	    	linkCnt = 1
    }
}
 
// check for existing duplicates link
if ( issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate') ) linkCnt += 1
 
// Transition requires at least one duplicates link
(linkCnt>=1)

 

 

 

thanks for sharing the complete code

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,276 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot