Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Check for link added during transition

Hello Team,

im trying to check if a type of link is added during transition,However it is not working.

Please help me on this.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.opensymphony.workflow.InvalidInputException
import webwork.action.ActionContext
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
def transit = false
if(issueLinkManager.getOutwardLinks(issue.id)*.issueLinkType.name.contains('Duplicate'))
{
transit = true
}
else
{
transit = false
def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField

def request = ActionContext.getRequest()
if (request) {
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue

if (!(issueLinkingValue.linkDescription == "Duplicate") && issueLinkingValue.linkedIssues.size() > 0))
{
transit = false

}
else {
transit = true
}
}
}
return transit

1 answer

Hi,

Could You please clarify how You added script in transition? Are You using validator?

In my jira next fragment work well.

issueLinkManager.getOutwardLinks(issue.getId())*.issueLinkType.name.contains('Duplicate')

Try add log.error(message) to debug script.

B.R.

Hello @Andrew ,

its a validator.

Hello @Andrew ,

we are checking if a link is already added or if the required type of link is added during the transition.

As you can see we are using the above code to achieve that.

in the above code the first part is working perfectly however i'm not able to figure how to check if a link is added during transition.

Please provide a solution, i can figure out what is wrong in my code.

Hi 

I checked on my local instance. If link 'duplicaties' added in transition validator throw exception. 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
import com.atlassian.jira.issue.fields.IssueLinksSystemField
import com.opensymphony.workflow.InvalidInputException
import webwork.action.ActionContext

def fieldManager = ComponentAccessor.getFieldManager()
def linksSystemField = fieldManager.getField("issuelinks") as IssueLinksSystemField

def request = ActionContext.getRequest()
if (request) {
def params = request.getParameterMap()
def issueLinkingValue = linksSystemField.getRelevantParams(params) as IssueLinksSystemField.IssueLinkingValue

if ((issueLinkingValue.linkDescription == "duplicates" && issueLinkingValue.linkedIssues.size() > 0)) {
throw new InvalidInputException(IssueFieldConstants.ISSUE_LINKS,
"You must not link a duplicates issue at this transition")
}
}

 

I based on this script https://scriptrunner.adaptavist.com/5.5.7/jira/recipes/workflow/validators/validate-attachments-links-in-transition.html

B.R.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you