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.
You could try
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
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 < ' + (myDate.plus(1).format("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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.