Skip to content

Block Jira opening ticket if custom field value is less than 1 #103

@lucafx93

Description

@lucafx93

Hello,

i need to block the creation of an issue if a custom field value is less than 1.

I tried with the attached code with no success, the custom field ID is: 13200.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.opensymphony.workflow.InvalidInputException;
import org.apache.log4j.Category;

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_13200")
def cFieldValue = issue.getCustomFieldValue(cField) as Integer

if (cFieldValue > 0){
log.debug("ERRORE, QUANTITA' NON DISPONIBILI");
throw "ERRORE";
throw new InvalidInputException("QUANTITA' NON DISPONIBILI");
return cFieldValue;
return false;
}

The log, due to its length, is attached to this request as a .txt file.

log.txt

That custom field is taken from another DB (linked via Elements) and it's the quantity of a particular item, if the quantity is less than 0 the ticket should throw an exception but it doesnt work as i would..

I'm putting this "Groovy inline script" in the validator the issue creation.

Thanks for your help,
Regards,

Luca

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions