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
}
}
Hey Yusuf,
According to the documentation, to disallow the transition you throw a new InvalidInputException
(com.opensymphony.workflow.InvalidInputException
).
regards, Thanos
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.