It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner validator to search for a JQL and compare

I'm trying to find out how to write a validation with scriptrunner that checks if there are any existing issues with the same date as I've put in to a custom date field.

I have a custom date field: "Change Scheduled Date"

When I transition my issue it should check if there are any other issues (JQL) with the same date value as in my issue. If so, the transition should be blocked with a message "There are already changes planned on this date"


Any assistance would be much appreciated. 


1 answer

1 accepted

0 votes
Answer accepted

You could try

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.ApplicationUsers

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
ApplicationUser user = userManager.getUserByName("soporte")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName('Start date')

def myDate = cf.getValue(issue) as Date

String JQL='createdDate >= ' + myDate.format("yyyy-MM-dd") + ' and createdDate < ' + ("yyyy-MM-dd"))

def query = jqlQueryParser.parseQuery(JQL)
if (searchProvider.searchCount(query, user)>0){
return false
return true

in a simple script validator

Change the user and the field name

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you