JIRA Validator to fire only on specific use cases

Majo June 4, 2020

Hi All,

I have written a groovy script Validator in Create transition to prevent Duplicate values for a customfield, and it is working fine.

Now there are some other use cases like Cloning the issue, Importing the issue using a Utility etc wherein the this Validator is getting fired (which is expected by my current design as I have put it in Create transition).

Is there a way I can modify the validator to work only when user is triggering the transition manually using Create Button ? It don't want it to work when we try to create issue by cloning or importer. Is it feasible. PFB my script.

 

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)

def searchProvider = ComponentAccessor.getComponent(SearchProvider)

def issueManager = ComponentAccessor.getIssueManager()

def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();

def cField = cfm.getCustomFieldObject("customfield_11151")

def cFieldValue = issue.getCustomFieldValue(cField)def projectName = issue.getProjectObject().getName()
if ( cFieldValue == null ) return true;
def query = jqlQueryParser.parseQuery("'Test Case ID' ~ '" + cFieldValue + "' AND 'PROJECT' = '" + projectName + "'" )
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
if (results.total == 0) return true;
else { results.getIssues().each { documentIssue -> invalidInputException = new InvalidInputException("Duplicate Test Case ID found in " + documentIssue.getKey());     return false;}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer