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
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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for sharing the complete code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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.