Edit Validation Did Not Worked

Hi,

 

I've added following code for behaviour plugin. I tried returning nothing, throwing invalid input exception and finally below code returning the error collection. Error occurs but jira completes edit operation successfully instead it should remain at Edit screen and show the error message added in the code. 

JIRA Version: 7.4.3

Script Runner: 5.1.6

 

-thank you very much

-yusuf

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.SimpleErrorCollection
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Issue issue=(Issue) issue

final String TESPIT_ISSUE_TYPE_NAME="Tespit"
final String ILGILI_TESPITLER_FIELD_NAME="İlgili Tespitler"
final Logger LOG=LoggerFactory.getLogger("tr.gov.tubitak.bilgem.yte.jira.groovy.validators.epid.EPIDIlgiliTespitlerForEditValidator")
CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager()
Collection<CustomField> customFieldCollection=cfm.getCustomFieldObjectsByName(ILGILI_TESPITLER_FIELD_NAME)
SimpleErrorCollection errorCollection = new SimpleErrorCollection()
if(customFieldCollection==null || customFieldCollection.size()!=1) {
errorCollection.addError(ILGILI_TESPITLER_FIELD_NAME,ILGILI_TESPITLER_FIELD_NAME+" alanı bulunamadı veya hatalı, sistem yöneticisine başvurunuz.")
return errorCollection
}

CustomField ilgiliTespitlerField=customFieldCollection.iterator().next()
Object object=issue.getCustomFieldValue(ilgiliTespitlerField)
if(object!=null) {
List<String> issueKeyList=(List<String>) object
List<String> invalidIssues=new ArrayList<String>()
IssueManager issueManager = ComponentAccessor.getIssueManager()
for(String issueKey:issueKeyList) {
Issue linkedIssue=issueManager.getIssueByCurrentKey(issueKey)
if(!linkedIssue.getIssueType().getName().equals(TESPIT_ISSUE_TYPE_NAME)) {
invalidIssues.add(linkedIssue.getKey()+":"+linkedIssue.getIssueType().getName())
}
}
if(invalidIssues.size()>0) {
LOG.error("Invalid issues exists, size: "+invalidIssues.size())
StringBuffer buffer=new StringBuffer()
buffer.append(ILGILI_TESPITLER_FIELD_NAME+" alanına sadece '"+TESPIT_ISSUE_TYPE_NAME+"' türünde talep seçilebilir:")
boolean first=true
for(String invalid:invalidIssues) {
if(!first)
buffer.append(" ,")
else {
buffer.append(" ")
first = false
}
buffer.append(invalid + "\n")
}
errorCollection.addError(ILGILI_TESPITLER_FIELD_NAME,buffer.toString())
return errorCollection
}
}

 

 

1 answer

Hey Yusuf, 

According to the documentation, to disallow the transition you throw a new InvalidInputException (com.opensymphony.workflow.InvalidInputException).

regards, Thanos

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,360 views 5 6
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you