Script Validator Based on a Customfield on which I test value

Deleted user June 21, 2017

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
Answer accepted
Deleted user June 21, 2017
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
TAGS
AUG Leaders

Atlassian Community Events