atlascommunity / jira-plugins-groovy

Jira Groovy plugin
https://atlasteam.ru
BSD 2-Clause "Simplified" License
66 stars 42 forks source link

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

Open lucafx93 opened 3 years ago

lucafx93 commented 3 years ago

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