Script Validator Based on a Customfield on which I test value Edited

Hi guys,

I am trying to develop a groovy script validator on the creation of my ticket : I need to check if one of my customfield contains the good issue type values. Here is my script, I don't find my mistake and I don't know where to find error message. I have this classical error message during the creation : We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file.

Here is my code : 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue



MutableIssue issue = issue

IssueManager issueManager = ComponentAccessor.getIssueManager();


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject((long) 25006)


def cfValue = issue.getCustomFieldValue(cf)
StreamAlright = true
for (int i = 0; i < cfValue.size(); i++) {
issue2 = issueManager.getIssueObject((String)cfValue[i])
if(Integer.parseInt(issue2.getIssueTypeId())!= 12800){
StreamAlright = false
break
}
}

StreamAlright != false || cfValue == null

1 answer

1 accepted

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.opensymphony.workflow.InvalidInputException
import  com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue

IssueManager issueManager = ComponentAccessor.getIssueManager();

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject((long) 25006)

def cfValue = issue.getCustomFieldValue(cf)
StreamAlright = true
for (int i = 0; i < cfValue.size(); i++) {
    issue2 = issueManager.getIssueObject((String)cfValue[i])
    if(Integer.parseInt(issue2.getIssueTypeId())!= 12800){
        StreamAlright = false
        break
    }
}

if (StreamAlright == true){
    return true
}
else{
    invalidInputException = new InvalidInputException("Please associate it to a Stream")
}

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

178 views 0 4
Read article

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