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

This widget could not be displayed.

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.

This widget could not be displayed.

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?

This widget could not be displayed.

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 Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

160 views 2 0
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