Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Scriptrunner validator on create transition for linked issues

Hi,

I have an issuetype A that on create is linked to issuetype B (the link is created with element copy & sync app, and also the issue)

My goal is to prevent a creation based on fields that are in the issue I want to link to.

I know that in the create transition the link is not exist yet, but the data is out there (in the end the issue is linked in this transition, and the linked issue B is already exist).

 

How to reach the link/ the issue I want to link to? I tried to use issueLinkManager but it's incorrect. Also I tried to get the linked issue field but it return empty.

 

Hope that I'm clear enough, happy for any help!

 

1 answer

1 accepted

0 votes
Answer accepted

In the end I found an answer.

Because its an issue that was not created yet, we need to "catch" the request and get the parameters from it. For this we need to use:

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 == "blocks" && issueLinkingValue.linkedIssues.size() > 0)) {
        throw new InvalidInputException(IssueFieldConstants.ISSUE_LINKS,
            "You must link a blocker issue at this transition")
    }
}

 

I used the params array to get the sourceissueid (the issue I want to create from) and from there I continued with JQL to find the links that exist and my logic for this validator.

Notice: I didn't use issueLinkingValue, I uploaded the code I found, maybe it will help someone else.

Suggest an answer

Log in or Sign up to answer