Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner validate linked issue in create linked issue

Luca Andreatta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2023

Hi all,

I need to add a scriprunner validator in the Create linked issue function to check the status of the linked issue.

Is it possible to do it?

The problem is that in the validation phase, I cannot get any linked issue. Maybe this is a two phase function, where in the first the issue will be created and in the second the link will be added?

 

This is the function thai I use to get the linked issue by link name:

def getInwardIssueList(linkType, issue) {

    def result = new ArrayList();

    List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());

    for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {

        IssueLink issueLink = (IssueLink) outIterator.next();

        //log.error(issueLink.getIssueLinkType().getName())

        if (issueLink.getIssueLinkType().name == linkType) {

            //def linkedIssue = issueLink.getDestinationObject()

            def linkedIssue = issueLink.getSourceObject()

            String type = linkedIssue.getIssueType().getName();

            result.add(linkedIssue);

        }

    }

    return result;

}

1 answer

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2023

Correct, the "Create Issue Link" appears to act as a wrapper between two other user tasks. 

1) Create an issue (with access to validators, post function and everything else in the workflow)

2) Create an Issue Link (which doesn't execute any workflow feature).

With scriptrunner, you can create a listener that will check for IssueLinkCreatedEvent, but you can't interrupt the link creation. The issue has long since been created and the link creation is also complete. 

At this point, if your validations fail, you can 1) delete the link, 2) Comment on the source or target issue.

Another option would be to subvert the "create issue link" function completely (hide it with a scriptrunner fragment) and add a workflow transition that will clone the issue using a post function. There, you will have the opportunity to validate some input and decide whether to allow cloning and linking to proceed.

Suggest an answer

Log in or Sign up to answer