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

This widget could not be displayed.
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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

523 views 3 19
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