Forums

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

Workflow Validator upon Jira Issue creation.

Sreedevi Raman Pisharody July 2, 2023

Hello Team,

I am trying to create a workflow validator wherein it will check the status of the Epic issue type linked to the issue and ensures it is in either Open, In Progress or Ready statuses only. In case of any other status it should not allow the creation.

Below script is what i am using

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.link.IssueLink

def issueManager = ComponentAccessor.issueManager

// Get the Epic link issue

def epicLink = ComponentAccessor.issueLinkManager.getInwardLinks(issue.id).find { link -> link.issueLinkType.name == "Epic Link" }

if (epicLink) { def epicIssue = epicLink.sourceObject

// Check the status of the Epic issue

def epicStatus = epicIssue.getStatus().getName()

if (!["Open", "In Progress", "Ready"].contains(epicStatus))

{

return false

}

} return true

 

This is added in simple scripted validator by scriptrunner at the time of Issue creation.

But the script is failing to validate the condition i am looking for. 

Can you let me know if i am making some mistake.

Thanks in advance.

3 answers

1 accepted

3 votes
Answer accepted
Evgenii
Community Champion
July 2, 2023

Hi, @Sreedevi Raman Pisharody 

Try this, checked it in my instance, it must work :)

/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/

import com.atlassian.jira.issue.Issue

Issue epicIssue = cfValues['Epic Link'] as Issue

if (epicIssue) {
String epicStatus = epicIssue.getStatus().getName()
if (!(epicStatus in ["Open", "In Progress", "Ready"])) {
return false
}
}
return true
Craig Nodwell
Community Champion
July 2, 2023

Perfect thanks @Evgenii -> @Sreedevi Raman Pisharody this is exactly what I was talking about earlier.

Like Evgenii likes this
Sreedevi Raman Pisharody July 2, 2023

Thanks Evgeniy and Craig for your quick support, I tested it out and it worked.

1 vote
Craig Nodwell
Community Champion
July 2, 2023

Hi @Sreedevi Raman Pisharody it's Sunday, I don't have a test env.  Was thinking wouldn't it be better to check the field for the epic link value instead of the inward link since the issue isn't created yet...  again just a thought since I can't validate this.

Sreedevi Raman Pisharody July 2, 2023

Appreciate you responding even on Sunday. 

I will surely try to check it out and let you know. 

Again thanks for your response.

0 votes
Seifallah Bellassoued
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.
July 2, 2023

Dear @Sreedevi Raman Pisharody

 

As @Craig Nodwell said, the issue is not created yet. So it doesn't have an ID yet.

As workaroud, I gess to use the following line of code instead of using issueLinkManager

 

def epicLink = issue.getAllOutwardLinks().find { link -> link.issueLinkType.name == "Epic Link"}

Best Regards,

Seif,

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.9
TAGS
AUG Leaders

Atlassian Community Events