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

0 votes
Accepted answer
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 Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,443 views 0 8
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